-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
608 lines (487 loc) · 16.2 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
"===================== SETTINGS ======================
" {{{
syntax on
syntax sync minlines=256
set autochdir
set autoindent
set backspace=indent,eol,start
set enc=utf-8
set expandtab
set fenc=utf-8
set hlsearch
set incsearch
set laststatus=2
set list
set listchars=trail:_,eol:¬,tab:▸\
set modeline
set nocursorline " cursorline make vim slow with highlighting
set nofoldenable
set number
set shell=fish
set shiftwidth=4
set showcmd
set showmatch
set smartcase
set smartindent
set softtabstop=4
set spell
set spelllang=en,cjk
set splitright
set tabstop=4
set title
set textwidth=80
set virtualedit+=block
set wildmenu wildmode=list:full
set wrapscan
"set nowrap
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
" }}}
" ===================== MAPPINGS ======================
" {{{
" General
" noremap ; :
" noremap : ;
noremap Q gq
noremap <Space>h ^
noremap <Space>l $
noremap <Space>n %
inoremap jk <esc>
" Continuous increment/decrement
if v:version > 705 || (v:version > 704 && has('patch754'))
vnoremap <c-a> <c-a>gv
vnoremap <c-x> <c-x>gv
endif
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
" Search text selected on visual mode
vnoremap // y/<C-R>"<CR>
" timestamp
nnoremap <silent> ,dt :r !date "+\%Y-\%m-\%dT\%H:\%M:\%S\%z"<CR>
" fix highlights for $(..) in 'sh' script because it was not supported by sh
let g:is_bash = 1
" You can pop a vertical window to display grep results
" autocmd QuickFixCmdPost *grep* :vert 100 cwindow
autocmd QuickFixCmdPost *grep* cwindow
" See https://code.google.com/p/mintty/wiki/Tips#Mode-dependent_cursor_in_vim
let &t_ti.="\e[1 q"
" See http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" }}}
"===================== PLUGINS ======================
" {{{
call plug#begin('~/.vim/plugged')
" Basic
Plug 'ConradIrwin/vim-bracketed-paste'
Plug 'Yggdroot/indentLine'
Plug 'corylanou/vim-present', {'for' : 'present'}
Plug 'dhruvasagar/vim-table-mode'
Plug 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
Plug 'ervandew/supertab'
Plug 'junegunn/vim-easy-align'
Plug 'lambdalisue/fern.vim'
Plug 'lambdalisue/fern-hijack.vim'
Plug 'thinca/vim-quickrun'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/grep.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Completion
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
"Plug 'mattn/vim-lsp-settings'
" Lint
Plug 'dense-analysis/ale'
" Test
"
Plug 'vim-test/vim-test'
" Color
Plug 'w0ng/vim-hybrid'
" Tags
Plug 'preservim/tagbar'
" Status/Tabline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'airblade/vim-gitgutter'
" Erlang
Plug 'jimenezrick/vimerl'
Plug 'vim-erlang/vim-erlang-tags'
" D
Plug 'JesseKPhillips/d.vim'
" Markdown
Plug 'kannokanno/previm'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
" Python plugins
" HTML/JS plugins
Plug 'mattn/emmet-vim'
Plug 'othree/html5.vim'
Plug 'digitaltoad/vim-pug'
Plug 'pangloss/vim-javascript'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'cakebaker/scss-syntax.vim'
Plug 'hail2u/vim-css3-syntax'
Plug 'ap/vim-css-color'
Plug 'posva/vim-vue'
Plug 'leafgarland/typescript-vim'
Plug 'mustache/vim-mustache-handlebars'
Plug 'prettier/vim-prettier', {
\ 'do': 'npm install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'yaml', 'html'] }
" HashiVim
Plug 'hashivim/vim-terraform'
" Go
"Plug 'fatih/vim-go'
" Swift
Plug 'keith/swift.vim'
" PlantUML
Plug 'aklt/plantuml-syntax'
" bats
Plug 'vim-scripts/bats.vim'
" protobuf
Plug 'uber/prototool', { 'rtp':'vim/prototool' }
" graphql
Plug 'jparise/vim-graphql'
" kotlin
Plug 'udalov/kotlin-vim'
" ruby
Plug 'vim-ruby/vim-ruby'
" TOML
Plug 'cespare/vim-toml', { 'branch': 'main' }
" zig
Plug 'ziglang/zig.vim'
call plug#end()
" }}}
"===================== COLOR ======================
" {{{
set background=dark
set t_Co=256
let g:rehash256 = 1
if (has("termguicolors"))
set termguicolors
endif
let g:hybrid_use_iTerm_colors = 1
colorscheme hybrid
let &colorcolumn=join(range(81,1000),",")
highlight ColorColumn ctermbg=235
" vim-gitgutter color settings
let g:gitgutter_override_sign_column_highlight = 0
highlight clear SignColumn
" }}}
"===================== REGISTRATIONS ======================
" {{{
" https://github.com/prabirshrestha/vim-lsp/wiki/Servers
if executable('bash-language-server')
augroup LspBash
autocmd!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'bash-language-server',
\ 'cmd': {server_info->[&shell, &shellcmdflag, 'bash-language-server start']},
\ 'allowlist': ['sh'],
\ })
augroup END
endif
"" Register clangd C++ lanuage server.
if executable('clangd')
au User lsp_setup call lsp#register_server({
\ 'name': 'clangd',
\ 'cmd': {server_info->['clangd', '-background-index']},
\ 'whitelist': ['c', 'cpp', 'objc', 'objcpp', 'cc'],
\ })
endif
if executable('gopls')
au User lsp_setup call lsp#register_server({
\ 'name': 'gopls',
\ 'cmd': {server_info->['gopls']},
\ 'whitelist': ['go'],
\ })
autocmd BufWritePre *.go LspDocumentFormatSync
endif
" RLS is no longer supported. https://blog.rust-lang.org/2022/07/01/RLS-deprecation.html
" Need to install 'rust-analyzer'. https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary
if executable('rust-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'Rust Language Server',
\ 'cmd': {server_info->['rust-analyzer']},
\ 'whitelist': ['rust'],
\ })
endif
"" Use directory with package.json as root
if executable('typescript-language-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'javascript support using typescript-language-server',
\ 'cmd': {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
\ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json'))},
\ 'whitelist': ['javascript', 'javascript.jsx'],
\ })
endif
if executable('pyls')
au User lsp_setup call lsp#register_server({
\ 'name': 'pyls',
\ 'cmd': {server_info->['pyls']},
\ 'whitelist': ['python'],
\ })
endif
" }}}
"===================== PLUGIN SETTINGS ======================
" {{{
" ale
let g:airline#extensions#ale#enabled = 1
let g:ale_open_list = 1
let g:ale_linters = {
\ 'javascript': ['prettier', 'eslint'],
\ 'go': ['golint'],
\ 'proto': ['prototool-lint'],
\ 'rust': ['analyzer'],
\}
let g:ale_lint_on_text_changed = 'never'
let g:ale_cpp_cc_options = '-std=c++20 -Wall'
augroup CloseLoclistWindowGroup
autocmd!
autocmd QuitPre * if empty(&buftype) | lclose | endif
augroup END
" commentary.vim
autocmd FileType c,cpp,go,swift setlocal commentstring=//\ %s
"
" CurtineIncSw.vim
autocmd FileType c,cpp nnoremap <S-J> :call CurtineIncSw()<CR>
" emmet.vim
let g:emmet_html5 = 0 " Self-closing tag is needed.
let g:user_emmet_install_global = 0
let g:user_emmet_mode='inv' "enable all functions, which is equal to
let g:user_emmet_leader_key='<C-Y>'
autocmd FileType html,htmldjango EmmetInstall
" fern
nnoremap <silent> <Leader>1 :Fern . -drawer -toggle<CR>
function! s:init_fern() abort
" Define NERDTree like mappings
nmap <buffer> o <Plug>(fern-action-open:system)
endfunction
augroup fern-custom
autocmd! *
autocmd FileType fern call s:init_fern()
augroup END
" fzf
nnoremap <leader>: :Commands<CR>
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --hidden --ignore-case --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')
\ : fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'right:50%:hidden', '?'),
\ <bang>0)
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'source': 'rg --files --no-ignore-vcs'}, <bang>0)
" HashiVim
let g:terraform_align=1
" lsp
" let g:lsp_log_verbose = 1
" let g:lsp_log_file = expand('~/.cache/vim-lsp/vim-lsp.log')
" Minimap
let g:minimap_highlight='Visual'
let g:minimap_toggle='<leader>mt'
" NERDTree
" nnoremap <silent> <Leader>1 :NERDTreeToggle<CR>
" let g:NERDTreeQuitOnOpen = 1 " Not working...
let g:NERDTreeMinimalUI = 1
let g:NERDTreeDirArrows = 1
let g:NERDTreeAutoDeleteBuffer = 1
let g:NERDTreeNaturalSort = 1
let g:NERDTreeSortHiddenFirst = 1
let g:NERDTreeSortOrder = ['README\.md$', '\.git.*$', '\/$', '*']
" open-browser
nmap <Leader>w <Plug>(openbrowser-smart-search)
" let g:netrw_nogx = 1 " disable netrw's gw mapping.
" plantuml-syntax
let g:plantuml_executable_script = "~/.plantuml/plantuml""
" quickrun.vim
let g:quickrun_config = get(g:, 'quickrun_config', {})
let g:quickrun_config._ = {
\ 'split': ':botright 16sp',
\ 'hook/time/enable': '1',
\ 'runner' : 'vimproc',
\ 'runner/vimproc/updatetime' : 60,
\ 'runner/python' : 60,
\ 'outputter' : 'error',
\ 'outputter/error/success' : 'buffer',
\ 'outputter/error/error' : 'quickfix',
\ 'outputter/buffer/close_on_empty' : 1,
\}
let g:quickrun_config.python = { 'command': 'python3' }
let g:quickrun_config.cpp = {
\ 'command': 'clang++',
\ 'cmdopt': '-std=c++20 -Wall'
\ }
au FileType qf nnoremap <silent><buffer>q :quit<CR>
let g:quickrun_no_default_key_mappings = 1
nnoremap <Leader>Q :cclose<CR>:write<CR>:QuickRun -mode n<CR>
xnoremap <Leader>Q :<C-U>cclose<CR>:write<CR>gv:QuickRun -mode v<CR>
nnoremap <expr><silent> <C-c> quickrun#is_running() ? quickrun#sweep_sessions() : "\<C-c>"
"
"" UltiSnips
" let g:UltiSnipsExpandTrigger="<Leader>s"
" let g:UltiSnipsJumpForwardTrigger="<c-b>"
" let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" " If you want :UltiSnipsEdit to split your window.
" let g:UltiSnipsEditSplit="vertical"
" " For conceal markers.
" if has('conceal')
" let g:tex_conceal=''
" " set conceallevel=2 concealcursor=niv
" endif
" surround.vim
autocmd FileType html,htmldjango,css call s:SetSurroundHTML()
function! s:SetSurroundHTML()
let b:surround_{char2nr("v")} = "{{ \r }}"
let b:surround_{char2nr("{")} = "{{ \r }}"
let b:surround_{char2nr("%")} = "{% \r %}"
let b:surround_{char2nr("b")} = "{% block \1block name: \1 %}\n\r\n{% endblock \1\1 %}"
let b:surround_{char2nr("i")} = "{% if \1condition: \1 %}\n\r\n{% else %}\n{% endif %}"
let b:surround_{char2nr("w")} = "{% with \1with: \1 %}\r{% endwith %}"
let b:surround_{char2nr("f")} = "{% for \1for loop: \1 %}\r{% endfor %}"
let b:surround_{char2nr("c")} = "{% comment %}\r{% endcomment %}""
endfunction
autocmd FileType python call s:SetSurroundPython()
function! s:SetSurroundPython()
let b:surround_{char2nr("c")} = "\"\"\"\r\"\"\""
endfunction
autocmd FileType markdown call s:SetSurroundMarkdown()
function! s:SetSurroundMarkdown()
let b:surround_{char2nr("*")} = "**\r**"
let b:surround_{char2nr("_")} = "__\r__"
endfunction
" tagbar
nnoremap <silent> <Leader>0 :TagbarToggle<CR>
let g:tagbar_sort = 0
let g:tagbar_ctags_bin = '/opt/local/bin/uctags'
" vim-airline
let g:airline_theme = "luna"
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
" indentLine
let g:indentLine_color_term = 251
let g:indentLine_setConceal = 0
" vim-markdown
let g:vim_markdown_conceal = 0
let g:vim_markdown_toc_autofit = 1
let g:vim_markdown_new_list_item_indent = 2
autocmd FileType markdown call s:SetMarkDown()
function! s:SetMarkDown()
nnoremap <silent> <Leader>0 :Toc<CR>
endfunction
" vim-easy-align
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
let g:easy_align_ignore_groups = ['String']
" vim-easytag
let g:easytags_file = '~/.vim/tags'
let g:easytags_async = 1
let g:easytags_always_enabled = 0
let g:easytags_include_members = 1
" vim-go
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
" vim-test
let test#strategy = "vimterminal"
" }}}
"===================== FILE TYPE ======================
" {{{
" C
autocmd FileType c,cpp setlocal tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
function! s:clang_format()
let now_line = line(".")
exec ":%! clang-format -style=WebKit"
exec ":" . now_line
endfunction
if executable('clang-format')
augroup cpp_clang_format
autocmd!
autocmd BufWrite,FileWritePre,FileAppendPre *.[ch]pp call s:clang_format()
autocmd BufWrite,FileWritePre,FileAppendPre *.[ch] call s:clang_format()
augroup END
endif
" bats
autocmd FileType bats setlocal tabstop=2 softtabstop=2 shiftwidth=2
" html
autocmd FileType html,htmldjango,css,javascript,json,sass,scss,vue,typescript,handlebars
\ setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
autocmd FileType html,htmldjango,css,sass,scss,vue
\ setlocal foldmethod=indent
" vue
autocmd FileType vue syntax sync fromstart
autocmd FileType vue setlocal nocursorline " Disable cursorline to make vim-vue fast
" shell
autocmd FileType sh setlocal tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
" erlang
autocmd BufRead,BufNewFile *.erl setlocal filetype=erlang
autocmd FileType erlang setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
autocmd BufWritePost *.erl call
\ vimproc#system_bg('~/.vim/bundle/vim-erlang-tags/bin/vim-erlang-tags.erl --otp')
" ruby
autocmd BufRead,BufNewFile *.podspec set filetype=ruby
autocmd BufRead,BufNewFile Podfile set filetype=ruby
autocmd BufRead,BufNewFile *Fastfile set filetype=ruby
autocmd FileType ruby setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" yaml
autocmd BufRead,BufNewFile *.yml set filetype=yaml
autocmd FileType yaml setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" HCL
autocmd FileType terraform setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" terraform
autocmd FileType terraform setlocal commentstring=#%s
" protobuf
autocmd FileType proto setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" go
autocmd FileType go setlocal tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
" swift
autocmd FileType swift setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab
" dart
autocmd FileType dart setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" markdown
autocmd FileType markdown setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" vim
autocmd FileType vim setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" }}}
"===================== Custom vimscript ======================
" {{{
" Based http://blog.erw.dk/2016/04/19/entering-dates-and-times-in-vim/
nnoremap <leader>t a<C-R>=strftime("%H:%M")<CR><Esc>
nnoremap <leader>d a<C-R>=strftime("%Y-%m-%d")<CR><Esc>
nnoremap <leader>l a<C-R>=strftime("%Y-%m-%d %H:%M")<CR><Esc>
" Fro vim-test
nmap <silent> <leader>u :TestNearest<CR>
nmap <silent> <leader>U :TestFile<CR>
nmap <silent> <leader>a :TestSuite<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
" Automatically removing all trailing whitespace
autocmd FileType c,cpp,js,ts,go,swift autocmd BufWritePre <buffer> %s/\s\+$//e
" [Multiple Cursors](http://www.kevinli.co/posts/2017-01-19-multiple-cursors-in-500-bytes-of-vimscript/)
let g:mc = "y/\\V\<C-r>=escape(@\", '/')\<CR>\<CR>"
" From http://www.kevinli.co/posts/2017-01-19-multiple-cursors-in-500-bytes-of-vimscript/#changing-a-visual-selection
" Replace a selection: selector<C-v>, type cn, do your change, then n to go next occurence, and . to replay the change
nnoremap cn *``cgn
nnoremap cN *``cgN
vnoremap <expr> cn g:mc . "``cgn"
vnoremap <expr> cN g:mc . "``cgN"
vnoremap <c-a> <c-a>gv
vnoremap <c-x> <c-x>gv
" Key bindings for vim-lsp.
nn <silent> <c-j> :LspDefinition<cr>
nn <silent> <M-r> :LRspReferences<cr>
nn <silent> <c-h> :LspHover<cr>
nn <silent> <Leader>R :LspRename<cr>
nn <silent> <M-a> :LspWorkspaceSymbol<cr>
nn <silent> <M-l> :LspDocumentSymbol<cr>
" }}}