-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.vimrc
More file actions
496 lines (411 loc) · 14.8 KB
/
.vimrc
File metadata and controls
496 lines (411 loc) · 14.8 KB
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
""" Install vim plug
if empty(glob('~/.vim/autoload/plug.vim')) && executable('curl')
echom 'Installing Vim-Plug...'
echom ''
silent execute '!curl -fLo '.glob('~').'/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
set rtp+=~/.vim " fix windows support for .vim file
""" Plugins
call plug#begin()
Plug 'ConradIrwin/vim-bracketed-paste'
Plug 'djoshea/vim-autoread'
Plug 'erietz/vim-terminator'
Plug 'farhanmustar/gv.vim'
Plug 'preservim/tagbar'
Plug 'terryma/vim-smooth-scroll'
Plug 'ton/vim-bufsurf'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'vim-ctrlspace/vim-ctrlspace'
" LSP
if !empty($USE_COC)
Plug 'neoclide/coc.nvim', {'branch': 'release'}
endif
" Linting
Plug 'vim-autoformat/vim-autoformat'
if !empty($USE_ALE)
Plug 'dense-analysis/ale'
endif
" HTML
Plug 'alvan/vim-closetag'
Plug 'AndrewRadev/tagalong.vim'
" Typescript
Plug 'leafgarland/typescript-vim'
" Astro
Plug 'wuelnerdotexe/vim-astro'
" Svelte
Plug 'leafOfTree/vim-svelte-plugin'
" Golang
"Plug 'fatih/vim-go'
" Rust
Plug 'rust-lang/rust.vim'
" Terraform
Plug 'hashivim/vim-terraform'
" Puppet
Plug 'rodjek/vim-puppet'
" Markdown
Plug 'dhruvasagar/vim-table-mode'
" RestructuredText
Plug 'erisian/rest_tools'
" TOML
Plug 'cespare/vim-toml'
" Coverage result visualization
Plug 'google/vim-maktaba'
Plug 'google/vim-coverage'
call plug#end()
""" General settings
" Inherit aliases from ~/.bash_aliases
let $BASH_ENV = "~/.bash_aliases"
" Switch to a color scheme for dark background
set background=dark
" Fix diff color scheme
highlight DiffText term=reverse cterm=bold ctermbg=124 gui=bold guibg=Red3
" Change auto-complete color scheme
highlight Pmenu ctermbg=brown ctermfg=black
highlight PmenuSel ctermbg=green
" Prevent auto-indenting of comments
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" Let Vim jump to the last position when reopening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Open each buffer in its own tabpage
"au BufAdd,BufNewFile * nested tab sball
" Some tuning
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set mouse=a " Enable mouse usage (all modes)
set ruler
set number
set splitbelow
set splitright
set hidden
" Tabs settings
set expandtab
set softtabstop=0
set shiftwidth=2
set tabstop=2
" Make tab completion in command mode behave like in Bash
set wildmenu
set wildmode=longest,list
set wildignore=*.o,*.class,*.swp,*.swo,*.pyc
" set 'selection', 'selectmode', 'mousemodel' and 'keymodel' for MS-Windows
behave mswin
" Use tree view for netrw directory browsing
let g:netrw_liststyle=3
" Indentation config for html and htmldjango
let g:html_indent_inctags = 'body,head,tbody,p'
" Status line
set statusline=%<%f\ %h%m%r\ %{tagbar#currenttag('[%s]','','f','scoped-stl')}%=%-14.(%l,%c%V%)\ %P
" set statusline=%<%f\ %h%m%r\ %{tagbar#currenttag('[%s]','','f','scoped-stl')}\ %{tagbar#currenttagtype('(%s)','')}%=%-14.(%l,%c%V%)\ %P
" Quickfix folding
function! g:IsContinuation(lnum)
let line = getline(a:lnum)
return line[0:2] == '|| '
endfunction
function! s:QfJumpFromFold() abort
let l:first = foldclosed('.')
if l:first != -1
call cursor(l:first, 1)
elseif getline('.') =~# '^|| '
normal! [z
endif
execute "normal! \<CR>"
endfunction
function! s:LoclistToQuickfix() abort
let l:loclist = getloclist(0)
let l:title = get(getloclist(0, {'title': 1}), 'title', 'Location List')
call setqflist([], 'r', {'items': l:loclist, 'title': l:title})
lclose
cwindow
endfunction
au BufReadPost quickfix setlocal foldmethod=expr
au BufReadPost quickfix setlocal foldexpr=g:IsContinuation(v:lnum+1)?1:'<1'
au BufReadPost quickfix setlocal winheight=10
au BufReadPost quickfix setlocal winheight=1
""" Plugins settings
" vim-terminator
let g:terminator_split_fraction = 0.05
let g:terminator_runfile_map = {
\ "rust": "case \"$dir\" in " .
\ "*/src/bin/*) cargo run --bin $fileNameWithoutExt | sed '1i note: Output\\n --> Cargo.toml:1:1' >&2;; " .
\ "*/examples/*) cargo run --example $fileNameWithoutExt | sed '1i note: Output\\n --> Cargo.toml:1:1' >&2;; " .
\ "*/tests/*) cargo clippy --tests && echo 'note: Success\n --> Cargo.toml:1:1' >&2;; " .
\ "*) cargo clippy && echo 'note: Success\n --> Cargo.toml:1:1' >&2;; " .
\ "esac",
\ "svelte": "[ -n '$fileName ' ] && npm run lint >&2 && echo 'Success' >&2",
\ }
" tagbar
let g:tagbar_sort = 0
" vim-ctrlspace
let g:CtrlSpaceSaveWorkspaceOnExit = 1
let g:CtrlSpaceSaveWorkspaceOnSwitch = 1
let g:CtrlSpaceLoadLastWorkspaceOnStart = 1
let g:CtrlSpaceUseMouseAndArrowsInTerm = 1
let g:CtrlSpaceIgnoredFiles = '\v(tmp|temp|build|dist|env|node_modules|platforms|plugins|www\/lib)[\/]'
if executable('rg')
let g:CtrlSpaceGlobCommand = 'rg --color=never --files'
endif
" coc.nvim
if !empty($USE_COC)
set updatetime=300
set signcolumn=yes
let g:coc_disable_startup_warning = 1
let g:coc_global_extensions = ['coc-rust-analyzer']
endif
" ale
let g:ale_fixers = {'javascript': ['eslint']}
let g:ale_linters = {'rust': ['analyzer']}
" vim-autoformat
let g:autoformat_verbosemode = 1
" Disable fallbacks
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
"! astyle version 2.05 or higher is required
let g:formatdef_astyle_cpp = '"astyle --mode=c --style=allman --indent=spaces=2 --pad-oper --unpad-paren --pad-header --convert-tabs"'
let g:formatters_cpp = ['astyle_cpp']
"! sudo apt-get install python-autopep8
let g:formatdef_autopep8 = '"autopep8 - -aa --max-line-length=199 --ignore=E128"'
let g:formatters_python = ['autopep8']
"! sudo npm install -g @fsouza/prettierd
" Formatter for frontend frameworks
let g:formatdef_prettier = '"bash -c ''output=$(prettierd --stdin-filepath \"" . expand("%:p") . "\"" . (&textwidth ? " --print-width " . &textwidth : "") . " --tab-width=" . shiftwidth() . ") || { echo \"$output\" 1>&2; exit 1; }; echo \"$output\"''"' " bug fix: quote file path and redirect to stderr
let g:formatters_astro = ['prettier']
let g:formatters_css = ['prettier']
let g:formatters_html = ['prettier']
let g:formatters_javascript = ['prettier']
let g:formatters_json = ['prettier']
let g:formatters_markdown = ['prettier']
let g:formatters_scss = ['prettier']
let g:formatters_svelte = ['prettier']
let g:formatters_typescript = ['prettier']
" Formatter for golang
let g:formatters_go = ['goimports', 'gofmt_2']
" Formatter for rust
let g:formatdef_rustfmt = '"rustfmt --edition 2024"'
" Formatter for yaml
let g:formatters_yaml = ['prettier']
"! sudo npm install -g js-beautify
" Formatter for js, json, html and css.
let g:formatdef_jsbeautify_js = '"js-beautify -f - --jslint-happy -s 2 -n"'
" Use js-beautify for web formats inside ~/fms; fallback to prettier elsewhere.
function! s:set_project_formatters() abort
let l:cwd = fnamemodify(getcwd(), ':p')
if l:cwd =~# '^' . fnamemodify('~/fms', ':p')
let g:formatters_css = ['cssbeautify']
let g:formatters_html = ['jsbeautify_js']
let g:formatters_javascript = ['jsbeautify_js']
let g:formatters_scss = ['cssbeautify']
else
let g:formatters_css = ['prettier']
let g:formatters_html = ['prettier']
let g:formatters_javascript = ['prettier']
let g:formatters_scss = ['prettier']
endif
endfunction
autocmd VimEnter,DirChanged * call s:set_project_formatters()
" HTML
" vim-closetag and tagalong
let g:closetag_filetypes = 'html,htmldjango,astro,svelte'
let g:tagalong_additional_filetypes = ['astro', 'svelte']
" vim-svelte-plugin
let g:vim_svelte_plugin_use_typescript = 1
" vim-go
let g:go_bin_path = $HOME . "/.vim/plugged/vim-go/bin"
" rust.vim
let g:rustfmt_autosave = 1
" vim-puppet
let g:puppet_align_hashes = 0
" vim-table-mode
let g:table_mode_corner_corner='+'
let g:table_mode_header_fillchar='='
""" Shortcuts
" Use CTRL-S for saving.
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <Esc>:update<CR>gi
" CTRL-Z is Undo; not in cmdline though
noremap <C-Z> u
inoremap <C-Z> <C-O>u
" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
" Map CTRL-C to ESC, so that it triggers |InsertLeave| autocommand event
inoremap <C-C> <Esc>
" Insert mode shortcuts
inoremap II <Esc>I
inoremap AA <Esc>A
inoremap OO <Esc>O
" Move by virtual lines when used without a count
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
" Quickly select the text that was just pasted. This allows you to, e.g.,
" indent it after pasting.
noremap gV `[v`]
" Stay in visual mode when indenting. You will never have to run gv after
" performing an indentation.
vnoremap < <gv
vnoremap > >gv
" Make Y yank everything from the cursor to the end of the line. This makes Y
" act more like C or D because by default, Y yanks the current line (i.e. the
" same as yy).
noremap Y y$
" Avoid pressing shift key to switch to previous tab
noremap gr gT
" Allows you to easily replace the current word and all its occurrences.
nnoremap <Leader>rc :%s/\<<C-r><C-w>\>/
vnoremap <Leader>rc y:%s/<C-r>"/
" Allows you to easily change the current word and all occurrences to something
" else. The difference between this and the previous mapping is that the mapping
" below pre-fills the current word for you to change.
nnoremap <Leader>cc :%s/\<<C-r><C-w>\>/<C-r><C-w>
vnoremap <Leader>cc y:%s/<C-r>"/<C-r>"
" Allow you to easily search the current word.
nnoremap <Leader>ff /\<<C-r><C-w>\><CR>
vnoremap <Leader>ff y/<C-r>"<CR>
nnoremap <Leader>fg :lgrep -rn "\<<C-r><C-w>\>" '<C-r>=expand('%:p:h')<CR>/'
vnoremap <Leader>fg y:lgrep -rn "<C-r>"" '<C-r>=expand('%:p:h')<CR>/'
nnoremap <Leader>fh :lgrep -rn "\<<C-r><C-w>\>" '<C-r>=expand('%:p:h')<CR>/'<CR>:lw<CR>
vnoremap <Leader>fh y:lgrep -rn "<C-r>"" '<C-r>=expand('%:p:h')<CR>/'<CR>:lw<CR>
nnoremap <Leader>fH :lgrep -rn "\<<C-r><C-w>\>" '<C-r>=expand('%:p:h')<CR>/'<CR>:tab lw<CR>
vnoremap <Leader>fH y:lgrep -rn "<C-r>"" '<C-r>=expand('%:p:h')<CR>/'<CR>:tab lw<CR>
nnoremap <Leader>gf :Glgrep! "\<<C-r><C-w>\>"<CR>:lw<CR>
vnoremap <Leader>gf y:Glgrep! "<C-r>""<CR>:lw<CR>
nnoremap <Leader>gF :Glgrep! "\<<C-r><C-w>\>"<CR>:cclose<CR>:tab lw<CR>:top split<CR>
vnoremap <Leader>gF y:Glgrep! "<C-r>""<CR>:cclose<CR>:tab lw<CR>:top split<CR>
noremap <Leader>l :tab lw<CR>:top split<CR>
" Quickfix shortcuts
au BufReadPost quickfix nnoremap <buffer><lt> zc
au BufReadPost quickfix nnoremap <buffer>> zo
au BufReadPost quickfix nnoremap <buffer>= za
au BufReadPost quickfix nnoremap <buffer><silent> <CR> :call <SID>QfJumpFromFold()<CR>
nnoremap [q :cprev<CR>
nnoremap ]q :cnext<CR>
nnoremap [Q :cfirst<CR>
nnoremap ]Q :clast<CR>
" Location list shortcuts
nnoremap <Leader>q :call <SID>LoclistToQuickfix()<CR>
nnoremap [w :lprev<CR>
nnoremap ]w :lnext<CR>
nnoremap [W :lfirst<CR>
nnoremap ]W :llast<CR>
" Diff shortcuts
noremap <leader>df :call DiffToggle()<CR>
noremap <leader>dt :call DiffToggleOne()<CR>
function! DiffToggle()
let currwin=winnr()
if &diff
diffoff!
windo setlocal nocursorbind
else
windo call DiffThis()
endif
" restores current window
execute currwin . 'wincmd w'
endfunction
function! DiffThis()
if &filetype != 'fugitive' && &filetype != 'qf'
diffthis
endif
endfunction
function! DiffToggleOne()
if &diff
diffoff
else
diffthis
endif
endfunction
" Remove trailing whitespaces
noremap <leader>as :%s/\s\+$//e<CR>
" Hard mode - disable arrow keys
map <Up> :echo "no!"<cr>
map <Down> :echo "no!"<cr>
map <Left> :echo "no!"<cr>
map <Right> :echo "no!"<cr>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
" Disable Execute Mode
nmap Q <NOP>
""" Plugin shortcuts
" vim-terminator shortcuts
nmap <F10> <leader>rf
" tagbar shortcuts
nmap <F12> :TagbarToggle<CR>
" vim-smooth-scroll shortcuts
noremap <silent> <c-y> :call smooth_scroll#up(3, 0, 3)<CR>
noremap <silent> <c-e> :call smooth_scroll#down(3, 0, 3)<CR>
noremap <silent> <c-u> :call smooth_scroll#up(&scroll, 20, 2)<CR>
noremap <silent> <c-d> :call smooth_scroll#down(&scroll, 20, 2)<CR>
noremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 20, 4)<CR>
noremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 20, 4)<CR>
" vim-bufsurf shortcuts
nmap <c-p> <Plug>(buf-surf-back)
nmap <c-n> <Plug>(buf-surf-forward)
" vim-fugitive shortcuts
" make Gvd (Gvdiffsplit) always open to the left
command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gvd exe fugitive#Diffsplit(0, <bang>0, "vertical leftabove <mods>", <q-args>)
cnoreabbrev GBlame G blame
cnoreabbrev Gblame G blame
" coc.nvim shortcuts
if !empty($USE_COC)
" Use <c-space> to trigger completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent><nowait> [g <Plug>(coc-diagnostic-prev)
nmap <silent><nowait> ]g <Plug>(coc-diagnostic-next)
nnoremap <leader>gg :CocDiagnostics<CR>
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gh <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming
nmap <leader>rn <Plug>(coc-rename)
" Mappings for CoCList
" Show all diagnostics
nnoremap <silent><nowait> <leader>aa :CocCommand rust-analyzer.runFlycheck<CR>
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
endif
" vim-autoformat shortcuts
noremap <leader>af :Autoformat<CR>
" vim-coverage shortcuts
nnoremap <Leader>cv :CoverageToggle<CR>