-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
687 lines (530 loc) · 17.7 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
set shell=/bin/zsh
let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 0
set guicursor=
set title
" Removed in Neovim, keeping this for backwards compatibility
set mouse=a
set nolazyredraw
set nocompatible
set noswapfile
set eol
set listchars=eol:¬,tab:»\ ,extends:›,precedes:‹,nbsp:·,trail:·
set list
set shada='1000
" Scroll horizontally by 1 character instead of default half screen
" Move vertically by rows rather than lines (useful with long lines + wrap on)
nnoremap j gj
nnoremap k gk
" Navigate quickfix entries
map <S-C-j> :cn<CR>zz
map <S-C-k> :cp<CR>zz
" Automatically indent pasted text
" nnoremap p p=`]
"nmap =p p`[v`]==
"nmap =P P`[v`]==
set sidescroll=5
set scrolloff=1
set shortmess-=S
" Mouse support
set timeoutlen=1000 ttimeoutlen=0
set number
set norelativenumber
set noshowmode
" Use global statusline
" set laststatus=3
set showtabline=2
set linebreak
set nowrap
set showbreak=▶
set textwidth=120
set noshowmatch
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" No beep or flash
autocmd VimEnter * set vb t_vb=
set hidden
set sessionoptions=resize,winpos,winsize,buffers,tabpages,
set splitright
set splitbelow
" Encoding:
set langmenu=en_US.UTF-8
set encoding=utf-8
set fileencoding=utf-8
" Search:
set hlsearch
set ignorecase
set smartcase
set incsearch
set autoindent
set expandtab
set shiftwidth=2
set smartindent
set smarttab
set softtabstop=2
" Ruler:
" set ruler
set colorcolumn=120
" Live preview of Ex commands
set inccommand=nosplit
call plug#begin('~/.vim/plugged')
Plug 'xolox/vim-misc'
" Plug 'easymotion/vim-easymotion'
Plug 'ggandor/leap.nvim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'mbbill/undotree'
Plug 'lukas-reineke/indent-blankline.nvim', { 'branch': 'lua' }
Plug 'pechorin/any-jump.vim'
Plug 'junegunn/fzf.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
" Git integration:
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'iberianpig/tig-explorer.vim'
Plug 'rbgrouleff/bclose.vim'
" Plug 'itchyny/lightline.vim'
" Plug 'shinchu/lightline-gruvbox.vim'
" TODO:
Plug 'awetzel/elixir.nvim'
Plug 'Shougo/echodoc.vim'
Plug 'Shougo/context_filetype.vim'
" Comments:
Plug 'tpope/vim-commentary'
Plug 'ntpeters/vim-better-whitespace'
Plug 'tpope/vim-endwise'
Plug 'lmeijvogel/vim-yaml-helper'
Plug 'Einenlum/yaml-revealer'
Plug 'kassio/neoterm'
"Plug 'benekastah/neomake'
Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
" Plug 'prettier/vim-prettier'
Plug 'fatih/vim-go'
Plug 'cohama/lexima.vim'
Plug 'christoomey/vim-tmux-navigator'
Plug '907th/vim-auto-save'
" Plug 'folke/tokyonight.nvim'
Plug 'morhetz/gruvbox'
" Plug 'psliwka/vim-smoothie'
Plug 'ap/vim-you-keep-using-that-word'
Plug 'rhysd/git-messenger.vim'
Plug 'rhysd/clever-f.vim'
Plug 'jpalardy/vim-slime'
Plug 'francoiscabrol/ranger.vim'
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
" Useful status updates for LSP
Plug 'j-hui/fidget.nvim'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-treesitter/nvim-treesitter-context'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
" Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" Plug 'hrsh7th/nvim-compe'
" Plug 'andersevenrud/compe-tmux', { 'branch': 'compe' }
Plug 'nvim-lua/plenary.nvim'
Plug 'pmizio/typescript-tools.nvim'
Plug 'L3MON4D3/LuaSnip', {'tag': 'v2.*', 'do': 'make install_jsregexp'}
Plug 'luukvbaal/stabilize.nvim'
" Plug 'folke/trouble.nvim'
Plug 'folke/lsp-colors.nvim'
" Solidity
Plug 'thesis/vim-solidity'
" Center buffer contents horizontally
Plug 'folke/zen-mode.nvim'
" Search improvements
Plug 'kevinhwang91/nvim-hlslens'
" Misc functionality
Plug 'echasnovski/mini.nvim'
Plug 'godlygeek/tabular'
call plug#end()
" let g:indentLine_char_list = ['|', '¦', '┆', '┊']
" let $NVIM_TUI_ENABLE_TRUE_COLOR=1
" if (has("termguicolors"))
set termguicolors
" endif
" set background=light
set background=dark
let g:gruvbox_contrast_dark = 'hard'
let g:gruvbox_contrast_light = 'hard'
" colorscheme tokyonight
colorscheme gruvbox
"Map leader to comma
let mapleader = ","
" Fzf
" nnoremap <silent> <C-p> :Files!<CR>
nnoremap <silent> <C-p> :GFiles!<CR>
nnoremap <silent> <C-l> :History!<CR>
nnoremap <silent> <C-\> :Lines!<CR>
nnoremap <silent> <C-g> :GFiles!?<CR>
let g:fzf_buffers_jump = 1
" Easymotion
let g:EasyMotion_do_mapping = 0
let g:EasyMotion_smartcase = 1
map <Leader>f <Plug>(easymotion-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)
map <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-overwin-w)
nmap <Leader>e <Plug>(easymotion-overwin-line)
" Auto remove trailing whitespaces on save
" let g:better_whitespace_enabled=0
" let g:strip_whitespace_on_save=1
" let g:strip_whitespace_confirm=0
" let g:strip_only_modified_lines=1
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--disabled', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
let spec = fzf#vim#with_preview(spec, 'right', 'ctrl-/')
call fzf#vim#grep(initial_command, 1, spec, a:fullscreen)
endfunction
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
nnoremap \ :Rg!<SPACE>
xnoremap \ y:Rg!<SPACE><C-r>"<CR>
let g:lightline = {
\ 'colorscheme': 'tokyonight',
\ }
" This function has very bad performance!!!
" let g:lightline = {
" \ 'colorscheme': 'tokyonight',
" \ 'component_function': {
" \ 'filename': 'LightlineFilename'
" \ },
" \ }
" function! LightlineFilename()
" let root = fnamemodify(get(b:, 'git_dir'), ':h')
" let path = expand('%:p')
" if path[:len(root)-1] ==# root
" return path[len(root)+1:]
" endif
" return expand('%')
" endfunction
set wildignore+=*/tmp/*,*.so,*.swp,*.zip
set signcolumn=auto
let g:gitgutter_preview_win_floating = 1
let g:gitgutter_grep = 'rg'
nnoremap <leader>gg :GitGutterPreviewHunk<CR>
set cursorcolumn
set cursorline
set re=1
" Neomake on save
"autocmd! BufWritePost * Neomake
" Unified clipboard
if has('nvim')
set clipboard+=unnamedplus
endif
" Check file change every 4 seconds ('CursorHold') and reload the buffer upon detecting change
" set autoread
" au CursorHold * checktime
" Tab completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" Center screen on next/previous selection.
nmap <silent> n /<CR>zz
nmap <silent> N ?<CR>zz
" Last and next jump should center too.
nnoremap <C-o> <C-o>zz
nnoremap <C-i> <C-i>zz
" Workaround for random text artifacts appearing after resizing tmux window
au VimResized * :redraw!
autocmd VimResized * exe "normal \<c-w>="
" Prevent first * from immediately jumping to the next occurrence
nnoremap * *``
" The escape key is a long ways away. This maps it to the sequence 'kj'
noremap! kj <esc>
nnoremap <esc> :noh<Enter>
noremap :W :w
"call neomake#configure#automake('w')
let g:tmux_navigator_no_mappings = 1
let g:tmux_navigator_save_on_switch = 2
" Disable tmux navigator when zooming the Vim pane
let g:tmux_navigator_disable_when_zoomed = 0
nnoremap <silent> <A-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <A-j> :TmuxNavigateDown<cr>
nnoremap <silent> <A-k> :TmuxNavigateUp<cr>
nnoremap <silent> <A-l> :TmuxNavigateRight<cr>
nnoremap <silent> <A-a> :TmuxNavigatePrevious<cr>
set updatetime=500 " Affects cursorhold
" let g:auto_save_events = ["CursorHold"]
" let g:auto_save = 1
set undofile " Maintain undo history between sessions
set undodir=~/.vim/undodir
let g:undotree_WindowLayout = 2
let g:undotree_HighlightChangedWithSign = 0
let g:undotree_HighlightChangedText = 0
let g:undotree_DiffAutoOpen = 0
let g:undotree_HelpLine = 0
let g:git_messenger_include_diff = 'current'
" Allow the . to execute once for each line of a visual selection
vnoremap . :normal .<CR>
let g:slime_target = 'tmux'
let g:slime_dont_ask_default = 1
let g:slime_default_config = {"socket_name": "default", "target_pane": "6"}
function! SendRspecToTmux() abort
" execute 'silent SlimeSend1 be spring rspec ' . expand('%:p') . ':' . line('.')
" execute 'silent SlimeSend1 spring bin/rails test ' . expand('%:p') . ':' . line('.')
execute 'silent SlimeSend1 spring rails test ' . expand('%:p') . ':' . line('.')
endfunction
nmap <Leader>r :call SendRspecToTmux()<CR>
" Annoying folding, I don't need a wannabe WYSIWYG in Vim -.-
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_conceal = 0
let g:instant_markdown_autostart = 0
let g:instant_markdown_browser = "chromium"
set textwidth=0 wrapmargin=0
" Join line above
nnoremap K kJ
lua <<EOF
require('leap').set_default_keymaps()
local luasnip = require('luasnip')
require("stabilize").setup()
require("mason").setup()
-- vim.g.tokyonight_style = "storm"
-- vim.g.tokyonight_italic_functions = true
require'nvim-treesitter.configs'.setup {
ensure_installed = "all", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = { "phpdoc" }, -- List of parsers to ignore installing
highlight = {
enable = true,
disable = {}, -- list of language that will be disabled
},
indent = {
enable = true
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<CR>',
scope_incremental = '<CR>',
node_incremental = '<TAB>',
node_decremental = '<S-TAB>',
},
},
}
require'treesitter-context'.setup{
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
}
vim.lsp.handlers["textDocument/publishDiagnostics"] =
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
underline = false,
virtual_text = { spacing = 10 },
signs = false,
update_in_insert = false
})
local nvim_lsp = require('lspconfig')
-- Finally, let's initialize the Elixir language server
-- Replace the following with the path to your installation
local path_to_elixirls = vim.fn.expand("~/Programming/elixir-ls/rel/language_server.sh")
nvim_lsp.elixirls.setup({
cmd = {path_to_elixirls},
capabilities = capabilities,
on_attach = on_attach,
settings = {
elixirLS = {
-- I choose to disable dialyzer for personal reasons, but
-- I would suggest you also disable it unless you are well
-- aquainted with dialzyer and know how to use it.
dialyzerEnabled = false,
-- I also choose to turn off the auto dep fetching feature.
-- It often get's into a weird state that requires deleting
-- the .elixir_ls directory and restarting your editor.
fetchDeps = false
}
}
})
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
nvim_lsp.solargraph.setup {
flags = {
debounce_text_changes = 150,
}
}
require("typescript-tools").setup {}
local servers = { "bashls", "solargraph" }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup { on_attach = on_attach }
end
--require("trouble").setup {
--icons = false;
--mode = "quickfix";
--}
vim.o.completeopt = "menu,menuone,noselect"
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<Tab>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require("zen-mode").setup {
window = {
backdrop = 1, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal
-- height and width can be:
-- * an absolute number of cells when > 1
-- * a percentage of the width / height of the editor when <= 1
-- * a function that returns the width or the height
width = 160, -- width of the Zen window
height = 1, -- height of the Zen window
-- by default, no options are changed for the Zen window
-- uncomment any of the options below, or add other vim.wo options you want to apply
options = {
-- signcolumn = "no", -- disable signcolumn
-- number = false, -- disable number column
-- relativenumber = false, -- disable relative numbers
-- cursorline = false, -- disable cursorline
-- cursorcolumn = false, -- disable cursor column
-- foldcolumn = "0", -- disable fold column
-- list = false, -- disable whitespace characters
},
},
plugins = {
-- disable some global vim options (vim.o...)
-- comment the lines to not apply the options
options = {
enabled = true,
ruler = false, -- disables the ruler text in the cmd line area
showcmd = false, -- disables the command in the last line of the screen
},
twilight = { enabled = true }, -- enable to start Twilight when zen mode opens
gitsigns = { enabled = false }, -- disables git signs
tmux = { enabled = false }, -- disables the tmux statusline
-- this will change the font size on kitty when in zen mode
-- to make this work, you need to set the following kitty options:
-- - allow_remote_control socket-only
-- - listen_on unix:/tmp/kitty
kitty = {
enabled = false,
font = "+4", -- font size increment
},
-- this will change the font size on alacritty when in zen mode
-- requires Alacritty Version 0.10.0 or higher
-- uses `alacritty msg` subcommand to change font size
alacritty = {
enabled = false,
font = "14", -- font size
},
},
-- callback where you can add custom code when the Zen window opens
on_open = function(win)
end,
-- callback where you can add custom code when the Zen window closes
on_close = function()
end,
}
require('hlslens').setup()
local kopts = {noremap = true, silent = true}
vim.api.nvim_set_keymap('n', 'n',
[[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]],
kopts)
vim.api.nvim_set_keymap('n', 'N',
[[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]],
kopts)
vim.api.nvim_set_keymap('n', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '<Leader>l', '<Cmd>noh<CR>', kopts)
-- Prevent stripping EOL on save
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead", "BufWritePost" }, {
pattern = "*",
command = "setl fixeol"
})
require('mini.colors').setup()
-- require('mini.animate').setup()
-- Triger `autoread` when files changes on disk
-- https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044
-- https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode
vim.api.nvim_create_autocmd({'FocusGained', 'BufEnter', 'CursorHold', 'CursorHoldI'}, {
pattern = '*',
command = "if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif",
})
-- Notification after file change
-- https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread
vim.api.nvim_create_autocmd({'FileChangedShellPost'}, {
pattern = '*',
command = "echohl WarningMsg | echo 'File changed on disk. Buffer reloaded.' | echohl None",
})
EOF
au FileType rb,ruby let b:prettier_exec_cmd = "rbprettier"
let g:ranger_replace_netrw = 1
let g:ranger_map_keys = 0
nmap - :Ranger<CR>
function! WriteRoomToggle()
let l:name = '_writeroom_'
if bufwinnr(l:name) > 0
wincmd o
else
let l:width = (&columns - &textwidth) / 5
execute 'topleft' l:width . 'vsplit +setlocal\ nobuflisted' l:name | wincmd p
execute 'botright' l:width . 'vsplit +setlocal\ nobuflisted' l:name | wincmd p
endif
endfunction
map <silent><Leader>v :call WriteRoomToggle()<CR>
noremap <Leader>q :tab split<CR>
set switchbuf="usetab"
set nofoldenable
" This is only needed for parcel
set backupcopy=yes
" Sort quickfix entries
function! s:CompareQuickfixEntries(i1, i2)
if bufname(a:i1.bufnr) == bufname(a:i2.bufnr)
return a:i1.lnum == a:i2.lnum ? 0 : (a:i1.lnum < a:i2.lnum ? -1 : 1)
else
return bufname(a:i1.bufnr) < bufname(a:i2.bufnr) ? -1 : 1
endif
endfunction
function SortUniqQFList()
let sortedList = sort(getqflist(), 's:CompareQuickfixEntries')
let uniqedList = []
let last = ''
for item in sortedList
let this = bufname(item.bufnr) . "\t" . item.lnum
if this !=# last
call add(uniqedList, item)
let last = this
endif
endfor
call setqflist(uniqedList)
endfunction
function! GitStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf('+%d ~%d -%d', a, m, r)
endfunction
" set statusline+=%{GitStatus()}
let g:vim_yaml_helper#auto_display_path = 0