-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
542 lines (441 loc) · 11.9 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
vim9script
plug#begin('~/.vim/plugged')
# Plugins
# https://github.com/junegunn/vim-plug
Plug 'https://git.sr.ht/~gnkv/vim-colors-off'
# Basic
Plug 'jlanzarotta/bufexplorer'
Plug 'tpope/vim-commentary'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'preservim/nerdtree'
Plug 'preservim/tagbar'
Plug 'tpope/vim-fugitive'
Plug 'mhinz/vim-signify'
Plug 'jreybert/vimagit'
Plug 'https://git.sr.ht/~gnkv/vim-gol'
Plug 'sebdah/vim-delve'
# LSP
Plug 'prabirshrestha/vim-lsp'
Plug 'lifepillar/vim-mucomplete'
plug#end()
# Standard VIM TUI Settings
set nocompatible
filetype off
filetype plugin indent on
syntax on
set t_Co=256
set t_ut=
colorscheme off
set encoding=utf-8
set wildmenu
set wildoptions-=pum
set wildignore+=*/.git/*,*/.direnv/*
set completeopt=menuone,popup,noselect
set nospell
set hidden
set noerrorbells
set novisualbell
set t_vb=
set modeline
set modelines=1
set mouse=a
set ignorecase
set smartcase
set nobackup
set nowb
set noswapfile
set noshowmode
set showmatch
set matchtime=2
set showcmd
set lazyredraw
set autoread
set scrolljump=1
set scrolloff=4
set backspace=2
set conceallevel=0
set nofoldenable
set number
set signcolumn=yes
set pumheight=20
set textwidth=120
set colorcolumn=120
set cursorline
set cursorcolumn
set pastetoggle=<F2>
set nopaste
set clipboard=unnamedplus
set listchars=tab:>\ ,nbsp:.,trail:.
set list
# Formatting options.
set wrap
set formatoptions=qrn1j
set autoread
set autoindent
set smartindent
set noexpandtab
set tabstop=4
set shiftwidth=4
set shiftround
set splitright
set splitbelow
set shortmess+=c
set laststatus=2
def g:StatusLineMode(): string
var modes = {
'n': 'NORMAL',
'i': 'INSERT',
'R': 'REPLACE',
'v': 'VISUAL',
'V': 'V-LINE',
"\<C-v>": 'V-BLOCK',
'c': 'COMMAND',
's': 'SELECT',
'S': 'S-LINE',
"\<C-s>": 'S-BLOCK',
't': 'TERMINAL'
}
return get(modes, mode(), '[NONE]')
enddef
set statusline=
set statusline+=%#Comment#[%n]%*
set statusline+=%#PmenuSel#\ %{g:StatusLineMode()}%{&paste?":PASTE":""}\ %* # mode and paste indicator
set statusline+=\ %.50f\ %m\ %r # filepath and modified flag
set statusline+=%=
set statusline+=%{&ff} # file format
set statusline+=\ \|\ %{&fenc!=#""?&fenc:&enc} # file enconding
set statusline+=\ \|\ %{&ft!=#""?&ft:"[none]"} # file type
set statusline+=\ \|\ %p%%\ %l:%c\ %* # percentage and lineinfo
# Fix cursor in INSERT mode.
&t_SI = "\e[5 q"
&t_EI = "\e[2 q"
# netrw
g:netrw_keepdir = 0
g:netrw_winsize = -35
g:netrw_banner = 0
g:netrw_list_hide = '^.git/$,^.direnv/$'
g:netrw_liststyle = 3
hi! link netrwMarkFile Search
hi! link netrwTreeBar Comment
def NetrwMapping()
nmap <buffer> H u
nmap <buffer> h -^
nmap <buffer> <Space> <CR>
nmap <buffer> . gh
enddef
autocmd filetype netrw NetrwMapping()
# No statusline in netrw window.
au FileType netrw setlocal statusline=%F
autocmd BufEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&filetype") == "netrw"
| quit
| endif
# Abbreviations.
cnoreabbrev Wq wq
cnoreabbrev Wa wa
# Non-plugin Keybindings:
# yank to the EOL
nnoremap Y y$
# delete without yanking
nnoremap <leader>d "_d
vnoremap <leader>d "_d
# replace selected text without yanking
vnoremap <leader>p "_dP"
# quotes
vnoremap <Leader>q" di""<Esc>P
vnoremap <Leader>q' di''<Esc>P
vnoremap <Leader>q` di``<Esc>P
vnoremap <Leader>q( di()<Esc>P
vnoremap <Leader>q[ di[]<Esc>P
vnoremap <Leader>q{ di{}<Esc>P
vnoremap <Leader>q< di<><Esc>P
noremap j gj
noremap k gk
# indent
nmap < <<
nmap > >>
vnoremap < <gv
vnoremap > >gv
nnoremap <F5> :set list!<CR>
inoremap <F5> <Esc>:set list!<CR>a
nnoremap <leader><space> :nohlsearch<CR>
# quickfix close
nnoremap <silent>qc :cclose<CR>
nnoremap <silent>qf :copen<CR>
# quickfix switch
nnoremap <Down> :cn!<CR>
nnoremap <Up> :cp!<CR>
nnoremap qn :cn!<CR>
nnoremap qp :cp!<CR>
# buffers switch
nnoremap fn :bn!<CR>
nnoremap fp :bp!<CR>
nnoremap fd :bd<cr>
# window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
# disable arrows
# noremap <Up> <NOP>
# noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
# expand opening-brace
inoremap {<CR> {<CR>}<Esc>O
# reload vimrc
nnoremap <leader>sv :source $MYVIMRC<CR>
nnoremap <leader>t :ter<CR>
# nnoremap <leader>e :Explore<CR>
hi SignColumn ctermbg=NONE guibg=NONE
hi SpellBad cterm=undercurl ctermbg=NONE guibg=NONE
hi Todo ctermbg=NONE guibg=NONE cterm=NONE gui=NONE
hi Error ctermbg=NONE guibg=NONE cterm=NONE gui=NONE
# trailing whitespaces
match ErrorMsg '\s\+$'
# Plug 'tpope/vim-commentary'
#
augroup commentstring
autocmd FileType c,h setlocal commentstring=//\ %s
augroup END
# Plug 'preservim/nerdtree'
#
g:NERDTreeDirArrows = 1
g:NERDTreeMinimalUI = 1
g:NERDTreeShowHidden = 1
g:NERDTreeMinimalMenu = 1
g:NERDTreeMapActivateNode = '<Space>'
g:NERDTreeWinSize = 40
g:NERDTreeDirArrowExpandable = '+'
g:NERDTreeDirArrowCollapsible = '-'
g:NERDTreeIgnore = [
'^\.git$',
'^\.direnv$',
'^bazel-.*$',
'^zig-.*$',
'^target$',
]
map <F3> :NERDTreeToggle<CR>
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') | quit | endif
# Plug 'preservim/tagbar'
#
nmap <F4> :TagbarToggle<CR>
# Plug 'mhinz/vim-signify'
#
g:signify_vcs_list = ['git']
g:signify_realtime = 1
g:signify_sign_show_count = 0
g:signify_sign_add = '+'
g:signify_sign_delete = '_'
g:signify_sign_delete_first_line = '‾'
g:signify_sign_change = '~'
g:signify_sign_changedelete = g:signify_sign_change
hi SignifySignAdd ctermbg=NONE guibg=NONE ctermfg=green guifg=green
hi SignifySignChange ctermbg=NONE guibg=NONE ctermfg=yellow guifg=yellow
hi SignifySignDelete ctermbg=NONE guibg=NONE ctermfg=red guifg=red
# Plug 'jreybert/vimagit'
#
g:magit_commit_title_limit = 72
nnoremap gm :Magit<CR>
# Plug 'ctrlpvim/ctrlp.vim'
#
g:ctrlp_working_path_mode = 'ra'
g:ctrlp_types = ['fil', 'buf']
g:ctrlp_user_command = 'rg --files --sort=none'
g:ctrlp_switch_buffer = 'e'
g:ctrlp_max_height = 20
# ripgrep
set grepprg=rg\ --vimgrep
set grepformat=%f:%l:%c:%m,%f:%l:%m
cnoreabbrev <expr> grep 'silent grep'
cnoreabbrev <expr> lgrep 'silent lgrep'
nnoremap <leader>g :silent grep! <C-R><C-W><CR>
augroup quickfix
autocmd!
autocmd QuickFixCmdPost [^l]* cwindow | call setqflist([], 'a')
autocmd QuickFixCmdPost [l]* lwindow | call setqflist([], 'a')
augroup END
# Plug 'lifepillar/vim-mucomplete'
#
g:mucomplete#enable_auto_at_startup = 1
g:mucomplete#completion_delay = 100
g:mucomplete#reopen_immediately = 1
g:mucomplete#chains = {
default: ['omni', 'keyn'],
sql: ['keyn']
}
g:mucomplete#can_complete = {
default: {
omni: (t) => strlen(&l:omnifunc) > 0 && t =~# '\%(\k\|->\|::\|\.\)$',
}
}
# mucomplete + vim-lsp
autocmd FileType go,rust setlocal omnifunc=lsp#complete
inoremap <leader>c <C-x><C-o>
# Plug 'prabirshrestha/vim-lsp'
#
# golang.org/x/tools/cmd/gopls
var gols = {
name: 'gopls',
cmd: (server_info) => ['gopls', 'serve'],
root_uri: (server_info) => lsp#utils#path_to_uri(
lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), ['go.mod', 'go.work'])
),
workspace_config: {
gopls: {
codelenses: {generate: v:false, gc_details: v:true},
hoverKind: 'FullDocumentation',
linksInHover: v:false,
staticcheck: v:true,
},
},
allowlist: ['go'],
languageId: (server_info) => 'filetype',
}
au User lsp_setup lsp#register_server(gols)
# https://github.com/rust-lang/rust-analyzer
var rls = {
name: 'rls',
cmd: (server_info) => ['rust-analyzer'],
root_uri: (server_info) => lsp#utils#path_to_uri(
lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), ['Cargo.toml'])
),
initialization_options: {
cargo: {
buildScripts: {
enable: v:true,
},
},
procMacro: {
enable: v:true,
},
},
allowlist: ['rust'],
}
au User lsp_setup lsp#register_server(rls)
# https://github.com/MaskRay/ccls
var cls = {
name: 'ccls',
cmd: (server_info) => ['ccls'],
root_uri: (server_info) => lsp#utils#path_to_uri(
lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), [
'.ccls',
'compile_commands.json',
'.clang-format'
])
),
initialization_options: {cache: {directory: expand('~/.cache/ccls')}},
allowlist: ['c', 'cpp'],
}
# au User lsp_setup lsp#register_server(cls)
# https://github.com/python-lsp/python-lsp-server
var pyls = {
name: 'pylsp',
cmd: (server_info) => ['pylsp'],
root_uri: (server_info) => lsp#utils#path_to_uri(
lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), ['.git'])
),
workspace_config: {pyls: {
configurationSources: ['flake8'],
}},
allowlist: ['python'],
}
# au User lsp_setup lsp#register_server(pyls)
# https://github.com/zigtools/zls
var zls = {
name: 'zls',
cmd: (server_info) => ['zls'],
root_uri: (server_info) => lsp#utils#path_to_uri(
lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), ['build.zig'])
),
workspace_config: {
enable_autofix: v:false,
warn_style: v:true,
},
allowlist: ['zig'],
}
# au User lsp_setup lsp#register_server(zls)
g:lsp_fold_enabled = 0
g:lsp_text_edit_enabled = 0
g:lsp_semantic_enabled = 0
g:lsp_diagnostics_echo_cursor = 1
g:lsp_diagnostics_virtual_text_enabled = 0
g:lsp_diagnostics_signs_error = {'text': 'x'}
g:lsp_diagnostics_signs_warning = {'text': 'w'}
g:lsp_diagnostics_signs_information = {'text': '@'}
g:lsp_diagnostics_signs_hint = {'text': '*'}
g:lsp_document_code_action_signs_hint = {'text': '>'}
g:lsp_format_sync_timeout = 1000
g:lsp_show_message_log_level = 'none'
g:lsp_log_file = expand('/tmp/lsp.log')
nnoremap <silent> gd :LspDefinition<CR>
nnoremap <silent> gds :sp<cr>:LspDefinition<cr>
nnoremap <silent> gdv :vsp<cr>:LspDefinition<cr>
nnoremap <silent> gtd :LspTypeDefinition<CR>
nnoremap <silent> gdc :LspDeclaration<cr>
nnoremap <silent> gi :LspImplementation<cr>
nnoremap <silent> gr :LspRename<CR>
nnoremap <silent> gf :LspDocumentFormat<CR>
nnoremap <silent> grf :LspDocumentRangeFormat<CR>
nnoremap <silent> ga :LspCodeAction --ui=float<CR>
nnoremap <silent> gl :LspCodeLens<CR>
nnoremap <silent> gn :LspNextError<CR>
nnoremap <silent> gp :LspPreviousError<CR>
nnoremap <silent> gx :LspReferences<CR>
nnoremap <silent> gh :LspHover<CR>
nnoremap <silent> gs :LspWorkspaceSymbol<CR>
nnoremap <silent> gth :LspTypeHierarchy<CR>
augroup autoformat
autocmd FileType go,rust,zig autocmd BufWritePre <buffer> :LspDocumentFormatSync
autocmd FileType go autocmd BufWritePre <buffer>
\ execute('LspCodeActionSync source.organizeImports')
autocmd FileType proto autocmd BufWritePre <buffer> g:Format('clang-format -assume-filename=foobar.proto')
# autocmd FileType c,h autocmd BufWritePre <buffer> g:Format('clang-format -assume-filename=foobar.c')
augroup END
def g:Format(formatter: string)
var winview = winsaveview()
var content = join(getbufline('%', 1, '$'), "\n")
var formatted = systemlist(formatter, content)
if v:shell_error == 0
deletebufline('%', 1, '$')
setline(1, [])
setbufline('%', 1, formatted)
else
echoerr printf('Formatting failed: %s', formatted)
endif
winrestview(winview)
enddef
command! -bang -nargs=* LspStartServer lsp#activate()
# Plug 'sebdah/vim-delve'
#
hi DlvPoint term=standout ctermbg=117 ctermfg=0 guibg=#BAD4F5 guifg=Black
g:delve_breakpoint_sign_highlight = 'DlvPoint'
g:delve_tracepoint_sign_highlight = 'DlvPoint'
g:delve_breakpoint_sign = '>>'
g:delve_tracepoint_sign = '||'
nnoremap <silent> drt :DlvTest<CR>
nnoremap <silent> drd :DlvDebug<CR>
nnoremap <silent> dtb :DlvToggleBreakpoint<CR>
nnoremap <silent> dtt :DlvToggleTracepoint<CR>
# Filetype config.
augroup filetypedetect
au FileType python setlocal et sts=4 tw=80 cc=80
au FileType yaml setlocal et sw=2 sts=2 ts=2
au FileType proto setlocal et sts=4
au FileType rst,markdown,text setlocal tw=80 cc=80 spell
au FileType mail setlocal tw=72 cc=72 spell
au FileType gitcommit setlocal tw=72 cc=72 spell
# Resize quickfix
au FileType qf resize 20
augroup END
## Custom functions.
# Print highlight group under the cursor.
def g:SynStack()
if !exists('*synstack')
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
enddef