forked from mlaursen/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
596 lines (471 loc) · 16.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
let s:plugged_autoload_prefix='~/.vim'
let s:plugged_install_dir='~/.vim/plugged'
if has('nvim')
let s:plugged_autoload_prefix='~/.local/share/nvim/site'
let s:plugged_install_dir='~/.local/share/nvim/plugged'
endif
let s:plugged_autoload_path=s:plugged_autoload_prefix . '/autoload/plug.vim'
if empty(glob(s:plugged_autoload_path))
let s:command='!curl -fLo ' . s:plugged_autoload_path . ' --create-dirs '
let s:command.='https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
silent exec s:command
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
function! MarkdownComposer(info)
if a:info.status == 'installed' || a:info.forced
if has('nvim')
silent! !cargo build --release
else
silent! !cargo build --release --no-default-features --features json-rpc
endif
endif
endfunction
" ================================================================
" => Initializing Plugins
" ================================================================
call plug#begin(s:plugged_install_dir)
" ==================================
" Formatting/colors
" ==================================
Plug 'editorconfig/editorconfig-vim'
Plug 'hail2u/vim-css3-syntax' " updates vim's built-in css to support CSS3
Plug 'cakebaker/scss-syntax.vim'
Plug 'pangloss/vim-javascript'
" I don't want the snippets provided by this package as I like my own vim-react-snippets
Plug 'HerringtonDarkholme/yats.vim', {'do': 'rm -rf UltiSnips'}
Plug 'maxmellon/vim-jsx-pretty'
" ==================================
" Linters, validators, and autocomplete
" ==================================
Plug 'alvan/vim-closetag'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'SirVer/ultisnips'
Plug 'mlaursen/vim-react-snippets'
Plug 'mlaursen/rmd-vim-snippets'
" ==================================
" File navigation
" ==================================
Plug 'junegunn/fzf', {'dir': '~/.fzf', 'do': './install --all'}
Plug 'junegunn/fzf.vim'
""Plug 'airblade/vim-rooter' " this changes the pwd to the project root
Plug 'scrooloose/nerdtree', {'on': ['NERDTreeToggle', 'NERDTreeFind']}
Plug 'Xuyuanp/nerdtree-git-plugin', {'on': ['NERDTreeToggle', 'NERDTreeFind']}
""Plug 'tpope/vim-fugitive'
" allows \bo to close all buffers except current focus
Plug 'vim-scripts/BufOnly.vim'
" ==================================
" Notes
" ==================================
Plug 'vimwiki/vimwiki', {'on': ['VimwikiDiaryIndex', 'VimwikiMakeDiaryNote']}
" ==================================
" General helpers and status bars
" ==================================
" allow focus events for auto-reloading buffers as needed
if has("nvim")
" this one appears to work with nvim while vitality works with vim. vitality is not preferred since it
" attempts to do cursor changes (yuck)
Plug 'tmux-plugins/vim-tmux-focus-events'
else
Plug 'sjl/vitality.vim'
endif
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat' " mostly used so that vim-surround can be repeated
Plug 'tpope/vim-commentary' " easy comments with `gc` or `gcc`
Plug 'matze/vim-move'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'euclio/vim-markdown-composer', {'do': function('MarkdownComposer'), 'on': 'ComposerStart'}
call plug#end()
" ================================================================
" vim-airline
" ================================================================
" update airline to use solarized
let g:airline_theme='solarized'
let g:airline_solarized_bg='dark'
" Always show the status bar and airline
set laststatus=2
set statusline=%<\ %f\ %m%r%y%w%=\ L:\ \%l\/\%L\ C:\ \%c\
set cmdheight=2
" ================================================================
" vim-javascript
" ================================================================
let g:javascript_plugin_jsdoc=1
" ================================================================
" coc.vim
" ================================================================
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
let g:coc_global_extensions=[
\ 'coc-css',
\ 'coc-pairs',
\ 'coc-scssmodules',
\ 'coc-docker',
\ 'coc-stylelintplus',
\ 'coc-eslint8',
\ 'coc-json',
\ 'coc-html',
\ 'coc-prettier',
\ 'coc-tsserver',
\ 'coc-yaml',
\ 'coc-vimlsp',
\ ]
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" quickly jump between diagnostics
nmap <silent> <C-k> <Plug>(coc-diagnostic-prev)
nmap <silent> <C-j> <Plug>(coc-diagnostic-next)
" show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
" goto definition
nmap <silent> gd <Plug>(coc-definition)
" goto type
nmap <silent> gK <Plug>(coc-type-definition)
" get references
nmap <silent> gr <Plug>(coc-references)
" format rename
nmap <silent> fr <Plug>(coc-rename)
" format file
nmap <silent> ff <Plug>(coc-format)
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" fix-it -- show preview window of fixable things and choose fix
nmap <silent>fi <Plug>(coc-codeaction)
" fix eslint (also any other fixable things. Mostly used for React hook dependencies)
nmap <silent>fe <Plug>(coc-fix-current)
" fix eslint (all)
nmap <silent>fE :<C-u>CocCommand eslint.executeAutofix<cr>
" fix imports
nmap <silent>fI :<C-u>CocCommand tsserver.organizeImports<cr>
" Show all diagnostics.
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Resume latest coc list.
nnoremap <silent> <space>r :<C-u>CocListResume<CR>
" ================================================================
" UltiSnips
" ================================================================
let g:UltiSnipsExpandTrigger='<c-space>'
" ================================================================
" NERDTree
" ================================================================
" hide more stuff in NERDTree
let g:NERDTreeShowHidden=1
" lazyily toggle nerdtree
nmap <leader>] :NERDTreeToggle<cr>
nmap <leader>F :NERDTreeFind<cr>
" ================================================================
" FZF
" ================================================================
" Allow fzf search as \t
nmap <leader>t :FZF<cr>
" Update fzf.vim actions for bindings like command-t
let g:fzf_action = {
\ 'ctrl-s': 'split',
\ 'ctrl-t': 'tabedit',
\ 'ctrl-v': 'vsplit',
\ }
let g:fzf_layout = { 'down': '~40%' }
" this allows the escape key to close the fzf window matching coc.nvim
if has("nvim")
au TermOpen * tnoremap <buffer> <Esc> <c-\><c-n>
au FileType fzf tunmap <buffer> <Esc>
endif
" ================================================================
" vim-move
" ================================================================
" update vim-move to use control instead of alt since mac is stupid
let g:move_key_modifier = 'C'
let g:move_map_keys = 0
let g:move_auto_indent = 0
vmap <C-j> <Plug>MoveBlockDown
vmap <C-k> <Plug>MoveBlockUp
" ================================================================
" vitality (for focus events)
" ================================================================
let g:vitality_fix_cursor=0
" ================================================================
" vim-jsx
" ================================================================
" allow jsx syntax in .js files
let g:jsx_ext_required=0
" ================================================================
" vim-closetag
" ================================================================
" Update closetag to also work on js and html files, don't want ts since <> is used for type args
let g:closetag_filenames='*.html,*.js,*.jsx,*.tsx'
let g:closetag_regions = {
\ 'typescript': 'jsxRegion',
\ 'typescriptreact': 'jsxRegion,tsxRegion',
\ 'typescript.tsx': 'jsxRegion,tsxRegion',
\ 'javascript.jsx': 'jsxRegion',
\ 'javascriptreact': 'jsxRegion',
\ }
" ================================================================
" vim-markdown-composer
" ================================================================
" only start markdown previewer after :ComposerStart
let g:markdown_composer_autostart=0
let g:markdown_composer_refresh_rate=-1
let g:markdown_composer_external_renderer='pandoc -f gfm -t html'
let g:markdown_composer_custom_css=['file://' . $HOME . '/dotfiles/theme.min.css']
autocmd FileType markdown nnoremap <buffer> <F12> :ComposerStart<cr>
" ================================================================
" VimWIKI
" ================================================================
let g:vimwiki_list = [{
\ 'path': '~/vimwiki/',
\ 'syntax': 'markdown',
\ 'ext': '.md'
\ }]
" ================================================================
" vim-rooter
" ================================================================
let g:rooter_patterns = ['.git', '_darcs', '.hg', '.bzr', '.svn', 'Makefile']
" ================================================================
" => General
" ================================================================
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
let mapleader = "\\"
let g:mapleader = "\\"
" change directory to folder of current file
"nnoremap <leader>cd :cd %:p:h<cr>
" turn backup off since it's handled by git
set nobackup
set nowb
set noswapfile
" Make it so that if files are changed externally (ex: changing git branches) update the vim buffers automatically
if !has("nvim")
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if !bufexists("[Command Line]") | checktime | endif
autocmd FileChangedShellPost *
\ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None
endif
" Make it so any .env files are correctly styled. Normally only worked with .env
autocmd BufNewFile,BufRead * if expand('%t') =~ '.env' | set filetype=sh | endif
" For some reason it stopped setting tw correctly
au FileType gitcommit setlocal tw=72
au BufRead,BufNewFile .babelrc,.eslintrc set ft=json
au BufRead,BufNewFile *nginx.conf.* set ft=nginx
" update scss files for SassDoc comments
au FileType scss set comments^=:///
" Use ag instead of ack
if executable('ag')
" Use ag for grepping
let g:ackprg='ag --vimgrep'
" grep visually selected text
vmap <leader>g y:Ag<space><C-R>"<cr>
nmap <leader>g :Ag<space>
" go to previous and next matches when using <leader>g
nmap <F9> :cp<cr>
nmap <F10> :cn<cr>
endif
" ================================================================
" => VIM user interface
" ================================================================
"Popup menu coloring
highlight Pmenu ctermbg=gray guibg=gray
highlight PmenuSel ctermbg=black guibg=black
highlight Pmenu ctermfg=black guifg=black
highlight PmenuSel ctermfg=white guibg=white
"highlight CocHintFloat ctermfg=DarkGreen guifg=DarkGreen
"highlight CocErrorFloat ctermfg=DarkRed guifg=DarkRed
"for all Coc popups together
highlight CocFloating ctermfg=DarkRed guifg=DarkRed
" Line Numbers
set nu
" Turn on the WiLd menu
set wildmenu
set cmdheight=2
" Always show the status bar and airline
set laststatus=2
" A buffer becomes hidden when it is abandoned (used for refactors)
set hidden
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" basic behavior
set hidden
" update tab behavior
set smartindent
set autoindent
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4
" line breaking
set lbr
set ai "Auto indent
set si "Smart indent
set wrap
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
"mouse
set mouse=a
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
"tags
"set tags+=/home/an/.vim/ctags
set tags+=tags;./src/tags;/
"for opening ctags in vertical split. The default C-W C-] opens in a
"horizontal split
map <C-W><C-\> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
"to automatically save/load folds
au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview
"netrw explorer tree view style
let g:netrw_liststyle = 3
"for showing list of buffers
nnoremap gb :ls<CR>:b<Space>
"remap for inserting closing brackets, etc.
inoremap << <<>><Left><Left>
inoremap <<<CR> <<
inoremap { {}<Left>
inoremap {<CR> {<CR>}<Esc>O
inoremap {{ {
inoremap {} {}
inoremap ' ''<Left>
inoremap '' '
inoremap " ""<Left>
inoremap "" "
inoremap [ []<Left>
inoremap [<CR> [<CR>]<Esc>O
inoremap [] []
inoremap [[ [
inoremap ( ()<Left>
inoremap (<CR> (<CR>)<Esc>O
inoremap (( (
inoremap () ()
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
cnoremap <C-h> <Left>
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-l> <Right>
" ================================================================
" => Colors and Fonts
" ================================================================
"colored nested brackets, braces, parentheses
let g:rainbow_active = 1
" Enable syntax highlighting
syntax enable
if has("termguicolors")
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
"let g:solarized_old_cursor_style=1
set background=dark
" silent! colorscheme desert
" let it fail quietly if it hasn't been installed yet
" silent! colorscheme solarized8
if has("nvim")
" Update cursor after the changes to nvim
set guicursor=n-v-c:block-Cursor/lCursor-blinkon0
set guicursor+=i-ci:block-Cursor/lCursor
set guicursor+=r-cr:hor20-Cursor/lCursor
else
set guicursor=
endif
" ================================================================
" => Files, backups and undo
" ================================================================
set undofile
set undodir=/home/an/.vim/undodir
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
" ================================================================
" => Moving around, tabs, windows and buffers
" ================================================================
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
map <leader>b :Buffers<cr>
map <leader>bd :Bclose<cr>
" Close all buffers except current
map <leader>bo :BufOnly<cr>
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" ================================================================
" => Spell checking
" ================================================================
" always enforce spell checking in text files
autocmd BufRead,BufNewFile *.txt,*.md,COMMIT_EDITMSG setlocal spell
" toggle spell checking for current file only
map <leader>ss :setlocal spell!<cr>
" linux doesn't do this by default, so enable it just to be safe
hi SpellBad cterm=underline