-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
722 lines (578 loc) · 22.3 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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
" ============= SETUP =============
let g:mapleader=' '
" Language settings (have to be before ä and ö mappings).
let $LANG='en_US'
set spelllang=en_us
set fileformats=unix,dos
set fileencodings=ucs-bom,utf-8,default,latin1
set encoding=utf-8
scriptencoding utf-8
" Vim file locations.
let VimFolder = '/.vim'
let PathToPluginsFolder = $HOME . VimFolder . '/plugins'
let PathToSpellFolder = $HOME . VimFolder . '/spell'
let PathToTempFolder = $HOME . VimFolder . '/.temp'
execute 'set spellfile=' . PathToSpellFolder . '/en.utf-8.add'
execute 'set viminfo+=n' . PathToTempFolder . '/.viminfo'
let &undodir = PathToTempFolder . '/undo'
let &backupdir = PathToTempFolder . '/backup'
let &directory = PathToTempFolder . '/swap'
let g:netrw_dirhistmax=0
" ============= PLUGINS =============
packadd! matchit " Enable the built-in plugin.
call plug#begin(PathToPluginsFolder)
Plug $HOMEBREW_PREFIX . '/opt/fzf'
Plug 'junegunn/fzf.vim' " Fuzzy file finding
Plug 'google/vim-searchindex' " Better search [x/y]
Plug 'terryma/vim-smooth-scroll' " Smooth scrolling
Plug 'machakann/vim-highlightedyank' " Highlight yanks
Plug 'markonm/traces.vim' " Live substitution
Plug 'easymotion/vim-easymotion' " Jump to any position
Plug 'simnalamburt/vim-mundo' " Graphical undotree
Plug 'tpope/vim-surround' " Edit braces easily
Plug 'tpope/vim-commentary' " Comment out lines
Plug 'tpope/vim-repeat' " Repeat plugin commands
Plug 'vim-scripts/ReplaceWithRegister' " Operator to replace text
Plug 'wellle/targets.vim' " More text objects
Plug 'tommcdo/vim-exchange' " Change two objects
Plug 'tpope/vim-abolish' " More advanced substitute etc
Plug 'tommcdo/vim-lion' " Alignment operator
Plug 'tpope/vim-eunuch' " Easy unix file operations
Plug 'tpope/vim-fugitive' " Git plugin
Plug 'rhysd/vim-grammarous' " Use LanguageTool to check spelling and grammar
Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' } " Live preview for LaTeX
Plug 'lervag/vimtex', { 'for': 'tex' } " LaTeX automompletion and more
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Filetypes
Plug 'jparise/vim-graphql'
Plug 'cespare/vim-toml'
Plug 'Glench/Vim-Jinja2-Syntax'
Plug 'hashivim/vim-terraform'
Plug 'kevinoid/vim-jsonc'
Plug 'darfink/vim-plist'
" Colorshemes
Plug 'lifepillar/vim-solarized8'
call plug#end()
" neoclide/coc.nvim
let g:coc_start_at_startup=0 " So we don't start Coc in vimdiff.
let g:coc_global_extensions = [
\ 'coc-clangd',
\ 'coc-docker',
\ 'coc-go',
\ 'coc-jedi',
\ 'coc-json',
\ 'coc-rls',
\ 'coc-sh',
\ 'coc-sql',
\ 'coc-tsserver',
\ 'coc-vimlsp',
\ 'coc-vimtex',
\ 'coc-yaml',
\]
let g:coc_filetype_map = {
\ 'bash': 'sh',
\}
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <TAB> pumvisible() ? "\<C-y>" : "\<TAB>"
nmap <silent> <expr> <C-N> &diff ? '/>>>>>>><CR><Esc>' : '<Plug>(coc-diagnostic-next)'
nmap <silent> <expr> <C-P> &diff ? '?<<<<<<<<CR><Esc>' : '<Plug>(coc-diagnostic-prev)'
xmap <silent> <expr> <C-N> &diff ? '/>>>>>>><CR><Esc><Esc>gv' : '<Plug>(coc-diagnostic-next)'
xmap <silent> <expr> <C-P> &diff ? '?<<<<<<<<CR><Esc><Esc>gv' : '<Plug>(coc-diagnostic-prev)'
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> <Leader>t <Plug>(coc-type-definition)
nmap <silent> <Leader>i <Plug>(coc-implementation)
nmap <silent> <Leader>u <Plug>(coc-references)
nnoremap <silent> <Leader>d :call <SID>show_documentation()<CR>
nmap <silent> <leader>r <Plug>(coc-rename)
xmap <silent> <leader>o <Plug>(coc-format-selected)
nmap <silent> <leader>o <Plug>(coc-format)
nnoremap <silent> <Leader>1 :<C-u>CocList diagnostics<cr>
nnoremap <silent> <Leader>a :<C-u>CocList commands<cr>
nnoremap <silent> <Leader>h :<C-u>CocList outline<cr>
nnoremap <silent> <Leader>s :<C-u>CocList -I symbols<cr>
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" lervag/vimtex
let g:vimtex_compiler_latexmk = {
\ 'options' : [
\ '-pdf',
\ '-shell-escape',
\ ],
\}
" rhysd/vim-grammarous
let g:grammarous#languagetool_cmd = 'languagetool'
" tpope/vim-surround
nmap S ysiW
" google/vim-searchindex
let g:searchindex_line_limit=100000000
" xuhdev/vim-latex-live-preview
let g:livepreview_previewer = 'open -a Skim'
let g:livepreview_use_biber = 1
" leaving this on makes the document flicker after just moving the cursor
let g:livepreview_cursorhold_recompile = 0
" junegunn/fzf.vim
nnoremap <Leader>f :Files<CR>
nnoremap <Leader>l :Lines<CR>
nnoremap <Leader>g :Helptags<CR>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>m :History<CR>
" easymotion/vim-easymotion
let g:EasyMotion_keys='asdghklqwertyuiopzxcvbnmfj'
let g:EasyMotion_do_shade=0
let g:EasyMotion_do_mapping=0
let g:EasyMotion_smartcase=1
hi link EasyMotionTarget2First EasyMotionTarget
map <Leader>k mo<Plug>(easymotion-bd-f)
" machakann/vim-highlightedyank
let g:highlightedyank_highlight_duration=300
" simnalamburt/vim-mundo
let g:mundo_preview_statusline='Diff'
let g:mundo_tree_statusline='History'
let g:mundo_mirror_graph=0
let g:mundo_return_on_revert=0
let g:mundo_verbose_graph=0
nnoremap <silent> <Leader>n :MundoToggle<CR>
" vim-scripts/ReplaceWithRegister
nmap ö <Plug>ReplaceWithRegisterOperator
nmap Ö <Plug>ReplaceWithRegisterOperator$
nmap öö <Plug>ReplaceWithRegisterLine
xmap ö <Plug>ReplaceWithRegisterVisual
" terryma/vim-smooth-scroll
nnoremap <silent> <C-U> :<C-U>call smooth_scroll#up(&scroll, 0, 4)<CR>
nnoremap <silent> <C-D> :<C-U>call smooth_scroll#down(&scroll, 0, 4)<CR>
nnoremap <silent> <C-B> :<C-U>call smooth_scroll#up(&scroll*2, 0, 6)<CR>
nnoremap <silent> <C-F> :<C-U>call smooth_scroll#down(&scroll*2, 0, 6)<CR>
" tpope/vim-fugitive
xnoremap <silent> <Leader>5 :Git blame<CR>
augroup FugitiveBlameMappings
autocmd!
autocmd BufEnter * if &filetype !=# 'fugitiveblame'
\| nnoremap <buffer> <silent> <Leader>5 :<C-U>Git blame<CR>
\| else
\| nnoremap <buffer> <silent> <Leader>5 :<C-U>quit<CR>
\| endif
augroup END
" wellle/targets.vim
" Prefer multiline targets around cursor over distant targets within cursor line.
let g:targets_seekRanges = 'cc cr cb cB lc ac Ac lr lb ar ab lB Ar aB Ab AB rr ll rb al rB Al bb aa bB Aa BB AA'
" darfink/vim-plist
" nttps://yous.be/2018/12/02/how-to-open-binary-plist-files-using-vim-plist/
function! s:ConvertBinaryPlist()
silent! execute '%d'
call plist#BufReadCmd()
set fileencoding=utf-8
augroup BinaryPlistWrite
autocmd! BufWriteCmd,FileWriteCmd <buffer>
autocmd BufWriteCmd <buffer> call plist#BufWriteCmd()
autocmd FileWriteCmd <buffer> call plist#FileWriteCmd()
augroup END
endfunction
augroup BinaryPlistRead
autocmd!
autocmd BufRead *
\ if getline(1) =~# '^bplist' |
\ call s:ConvertBinaryPlist() |
\ endif
autocmd BufNewFile *.plist set filetype=xml
augroup END
let g:loaded_plist = 1
let g:plist_display_format = 'xml'
let g:plist_save_format = ''
" ============= GENERAL =============
" Set these only when vim starts, not when sourcing vimrc.
if !exists('g:notfirstopen')
let g:notfirstopen=1
set termguicolors
set background=dark
let g:solarized_italics=0
colorscheme solarized8 " Messes up Mundo if loaded again.
if has('gui_running')
set lines=40 columns=120 " Initial window size.
" Changing font moves the window.
set guifont=Menlo:h16
endif
syntax enable
highlight Comment term=NONE ctermfg=10 gui=NONE guifg=#586e75
" Make solarized8 terminal and gui cursor the same color.
highlight Cursor ctermfg=15 ctermbg=4 guifg=#073642 guibg=#839496
" Remove light blug background from matching parenthesis.
highlight MatchParen term=reverse cterm=bold ctermbg=6 gui=bold guifg=#fdf6e3 guibg=NONE
" Make sure that the temp file locations exists.
if !isdirectory(PathToTempFolder)
call mkdir(PathToTempFolder)
endif
for folder in ['/undo', '/backup', '/swap']
if !isdirectory(PathToTempFolder . folder)
call mkdir(PathToTempFolder . folder, 'p')
endif
endfor
endif
if has('gui_running')
" GUI specific settings.
set guioptions=
" Cursor is a vertical bar in insert mode and a block in normal mode.
set guicursor+=a:blinkon0
set guicursor+=i-ci:ver20-blinkon0
else
" Terminal specific settings.
set mouse=a
if $TERM =~ "xterm-256color"
set ttymouse=sgr
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
let &t_SR = "\e[4 q"
endif
endif
" Visuals
set cursorline
set number
set showmode showcmd
set report=1
set cmdheight=2
set hlsearch
" Statusline
set laststatus=2 " Always show statusline
set statusline= " Clear statusline
set statusline+=%l " Current line number
set statusline+=/%L " Total lines
set statusline+=(%p%%) " Percentage through the file
set statusline+=%4c " Cursor column
set statusline+=\|%-4{strwidth(getline('.'))} " Line length
set statusline+=%{&buftype!='terminal'?expand('%:p:h:t').'/'.expand('%:t'):expand('%')} " dir/filename.ext
set statusline+=%m " Modified flag
set statusline+=%r " Read only flag
set statusline+=%= " Left/right separator
set statusline+=\ \|\ %{substitute(getcwd(),$HOME,'~','')} " Current working directory
set statusline+=\ [%{strlen(&ft)?(&ft\ .\ \',\'):''} " Filetype
set statusline+=%{strlen(&fenc)?(&fenc\ .\ \',\'):''} " File encoding
set statusline+=%{&ff}] " Line endings
set statusline+=%< " Start to truncate here
" Line wrapping
set wrap linebreak textwidth=0 wrapmargin=0
" Indentation settings
set tabstop=8 softtabstop=4 shiftwidth=4 expandtab
set smarttab autoindent breakindent
" Show unwanted whitespace on 'set list'.
set nolist listchars=tab:▷\ ,trail:•,nbsp:␣,eol:¬
" Search settings
set incsearch hlsearch ignorecase smartcase gdefault
" No errorbells
set noerrorbells
augroup NoVisualBells
autocmd!
autocmd GUIEnter * set visualbell t_vb=
augroup END
" Mixed settings
filetype plugin indent on " Auto detect filetype
let g:is_posix=1 " Make sh filetype be posix shell compliant
set clipboard=unnamed " Use system clipboard, unnamedplus doesn't work with gvim
set timeoutlen=1000 " Timeout for keymappings
set formatoptions=qlj " Don't autocontinue comment lines, remove comment when joining
set nojoinspaces " Don't put two spaces after a period when using `J` or `gq`
set pumheight=12 " Max height for the autocompletion popup
set nomodeline " Don't try to parse commands from opened file
set ttimeoutlen=0 " Remove delay from esc
set backspace=indent,eol,start " Make backspace behave normally
set hidden " Switch to another buffer without saving
set autoread " Update changes to file automatically
set scrolloff=1 " Pad cursor row with lines
set wildmode=list:longest,full " Better tab completion on command line mode
set undofile " Use an undofile for persistent undo
set undolevels=1000000000 " Remember more undo history
set history=10000 " Remember maximum amount of command history
set updatecount=10 " Update swap file more often
set matchpairs=(:),{:},[:],<:> " Configure which braces to match
set title " Show the current file in the window title
set titleold= " Restore the old window title after exiting
set updatetime=300 " Faster CursorHold events, mainly for coc.nvim
set signcolumn=number " Display coc.nvim marks in the number column instead of a dedicated one
set shortmess=SacO " S: no [x/y] when searching (plugin handles that)
" a: shorter prompt messages
" c: no ins completion messages
" O: no 'press enter' when opening multiple files in vimdiff
" ============= MAPPINGS =============
" Make j and k populate the jump list, when used with a count.
nnoremap <expr> j (v:count > 1 ? "m'" . v:count : '') . 'j'
nnoremap <expr> k (v:count > 1 ? "m'" . v:count : '') . 'k'
if has('gui_running')
" Move between splits (alt+hjkl).
nnoremap ← <C-W>h
nnoremap ↓ <C-W>j
nnoremap ↑ <C-W>k
nnoremap → <C-W>l
" Cycle tabs (alt+ui).
nnoremap <silent>ü :tabprevious<CR>
nnoremap <silent>↔︎ :tabnext<CR>
tnoremap ← <C-W><C-H>
tnoremap ↓ <C-W><C-J>
tnoremap ↑ <C-W><C-K>
tnoremap → <C-W><C-L>
tnoremap <silent>ü <C-W>:tabprevious<CR>
tnoremap <silent>↔︎ <C-W>:tabnext<CR>
else
" Move between splits (alt+hjkl).
nnoremap è <C-W>h
nnoremap ê <C-W>j
nnoremap ë <C-W>k
nnoremap ì <C-W>l
" Cycle tabs (alt+ui).
nnoremap <silent> õ :tabprevious<CR>
nnoremap <silent> é :tabnext<CR>
tnoremap è <C-W><C-H>
tnoremap ê <C-W><C-J>
tnoremap ë <C-W><C-K>
tnoremap ì <C-W><C-L>
tnoremap <silent> õ <C-W>:tabprevious<CR>
tnoremap <silent> é <C-W>:tabnext<CR>
endif
" Makes these easier to use.
noremap , :
tnoremap <C-W>, <C-W>:
noremap : ;
noremap ; ,
noremap g, g;
noremap g. g,
nnoremap + $
xnoremap + $
" Makes these more consistent with other commands.
nnoremap Y y$
nnoremap vv V
nnoremap V <C-V>$
" Cleaner to use when cursor doesn't move.
nnoremap J Jh
" Make K the logical opposite of J.
nnoremap K a<CR><Esc>k$
" Select previously yanked text.
nnoremap gb `[v`]
" Paste to the next or previous line.
nnoremap gp o<Esc>p^
nnoremap gP O<Esc>p^
" Go to the first occurrence of the symbol in the filename.
" (Can still use gF to open the file under the cursor.)
nnoremap <silent> gf :set nohlsearch<CR>"zyiwgg/\C\<<C-R>z\><CR>:set hlsearch<Bar>noh<CR>
" Fix the closest spell check error before the cursor and return back to writing.
" This is actually used with `CTRL + -`.
nnoremap <silent> <C-_> [s1z=``
inoremap <silent> <C-_> <Esc>[s1z=``a
" Substitute selected text.
xnoremap <Leader>7 "zy:%s/<C-R>=escape(@z,'/\')<CR>/
" Insert the current ISO date.
nnoremap <Leader>' a<C-R>=strftime("%Y-%m-%d")<CR><Esc>
" Easy way to run : command again for a visual selection.
xnoremap <Leader>' q:<UP>I'<,'><Esc>$
" Change enter behavior.
augroup EnterMappings
autocmd!
autocmd BufEnter * if &modifiable && &buftype !=# 'nofile' && &filetype !~# '^fugitive'
\| nnoremap <buffer> <silent> <CR> :<C-U>call <SID>BlankDown(v:count1)<CR>
\| nnoremap <buffer> <silent> <S-Enter> :<C-U>call <SID>BlankUp(v:count1)<CR>
\| endif
autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR>
augroup END
" Make C-U and C-W undoable.
inoremap <C-U> <C-G>u<C-U>
inoremap <C-W> <C-G>u<C-W>
" To ensure that the default behavior is kept after mapping tab.
nnoremap <C-I> <C-I>
" Better way to indent.
nnoremap <BS> <<
nnoremap <TAB> >>
xnoremap <BS> <gv
xnoremap <TAB> >gv
" Macvim doesn't support differentiating ctrl-i and tab, so keep this as a fallback.
nnoremap <C-K> <C-I>
" Persistent visuals.
xnoremap > >gv
xnoremap < <gv
xnoremap <C-X> <C-X>gv
xnoremap <C-A> <C-A>gv
" Q plays back q macro.
nnoremap Q @q
" Repeat the last substitution..
nnoremap & :&&<CR>
xnoremap & :s//~/&<CR>:noh<CR>
" Search for selected text.
xnoremap * "zy/\V<C-R>=escape(@z,'/\')<CR><CR>
xnoremap # "zy?\V<C-R>=escape(@z,'?\')<CR><CR>
" Easier substitution.
nnoremap <Leader>, :%s/
xnoremap <Leader>, :s/
" Split line on a comma.
nnoremap \ f,a<CR><Esc>^
" Split function arguments or list members into their own lines.
nnoremap <Leader>\ mq^f,`qv%J`qa<CR><Esc>k$%i<CR><Esc>k:s/, *\($\)\@!/,\r<CR>:noh<CR>`qv%=`q
" Type a delimiter for splitting the line into separate lines.
nnoremap <Leader><Leader>\ :s//&\r<Left><Left><Left><Left>
xnoremap <Leader><Leader>\ :s//&\r<Left><Left><Left><Left>
" Clear highlights.
" We need this noop mapping before, otherwise
" the esc mapping will just *completely* break.
nnoremap <Esc>\ <Esc>\
nnoremap <nowait> <silent> <Esc> <Esc>:noh<CR>
" Removes delay from closing fzf search popup.
tnoremap <Esc>\ <Esc>\
tnoremap <nowait> <silent> <Esc> <Esc>
" Open vimrc, ideavimrc, or cocconfig.
nnoremap <silent> <Leader>vr :e $MYVIMRC<CR>
nnoremap <silent> <Leader>vc :CocConfig<CR>
nnoremap <silent> <Leader>vi :e $HOME/.ideavimrc<CR>
nnoremap <silent> <Leader>] :windo diffthis<CR>
nnoremap <silent> <Leader>[ :windo diffoff<CR>
" ============= COMMANDS =============
" `vim-plug` commands.
command! PI silent! w | PlugInstall
command! PC silent! w | PlugClean!
command! PU w | PlugUpgrade | PlugUpdate | CocUpdate
" Source vimrc.
command! SO so $MYVIMRC
" Insert contents of command to buffer.
command! -nargs=1 RE call RED('<args>')
" Change the contents of a register.
command! -nargs=1 CR call ChangeReg('<args>')
" Change working directory to current file's directory.
command! CD cd %:p:h
" ============= FUNCTIONS =============
" https://github.com/dhleong/dots/blob/master/.vim/init/terminal.vim
function! RunCommandInSplitTerm(command) abort
write
let winSize = float2nr(0.3 * winheight('$'))
let mainBuf = bufnr('%')
let termBufNr = get(b:, '_run_term', -1)
let termWinNr = bufwinnr(termBufNr)
if termWinNr == -1
execute 'below split | resize ' . winSize
if termBufNr == -1 || bufexists(termBufNr) == 0
let termBufNr = term_start(&shell, {
\ 'curwin': 1,
\ 'term_finish': 'close',
\ })
call setbufvar(mainBuf, '_run_term', termBufNr)
else
execute 'buffer' . termBufNr
endif
else
execute termWinNr . 'wincmd w'
endif
let mainWin = bufwinnr(mainBuf)
call term_sendkeys(termBufNr, a:command . "\<CR>")
execute "normal \<C-W>p"
endfunction
" Insert blank lines before current line.
function! s:BlankUp(count) abort
norm! mq
for i in range(a:count)
execute "norm! O\<Esc>0\"_D"
endfor
norm! `q
endfunction
" Insert blank lines after current line.
function! s:BlankDown(count) abort
norm! mq
for i in range(a:count)
execute "norm! o\<Esc>0\"_D"
endfor
norm! `q
endfunction
" Redirect command's output to the current line.
function! RED(command)
redir => output
silent execute a:command
redir END
let @z = substitute(output, '^\n', '', '')
put z
return ''
endfunction
function! ChangeReg(x) abort
call feedkeys("q:ilet @" . a:x . " = \<c-r>\<c-r>=string(@" . a:x . ")\<cr>\<esc>0f'", 'n')
endfunction
" Settings that are ran after vim -c '<command>' is exeuted, so after git mergetool has finished its setup.
function! NewPostLaunchSettings(pathToSpellFolder) abort
let context = {'pathToSpellFolder': a:pathToSpellFolder}
function! context.f()
if !&diff
" Rebuild the spell file if the word list has changed
" but only if not using vim as git mergetool.
" This avoids an annoying error when the spell file has
" conflict markers which result in a syntax error.
for d in glob(self.pathToSpellFolder . '/*.add', 1, 1)
if filereadable(d) && (!filereadable(d . '.spl') || getftime(d) > getftime(d . '.spl'))
silent execute 'mkspell! ' . fnameescape(d)
endif
endfor
" Enable coc.nvim only when not running vimdiff, so it doesn't complain about conflict markers.
CocStart
set splitright " Open splits to the right
set splitbelow " Open splits to the bottom
else
syntax off
" Patches in: https://github.com/git/git/commit/f3d7623a13566048c4a48b9db6bb09765588a735
set nosplitright
set nosplitbelow
endif
endfunction
return context
endfunction
" ============= AUTOCMD =============
" Source vimrc when it's saved.
augroup ReloadVimrc
autocmd!
autocmd BufWritePost *vimrc so $MYVIMRC
augroup END
" Open help windows in a new tab.
augroup HelpOpen
autocmd!
autocmd BufRead *.txt if &buftype ==? 'help'
\|execute "normal \<C-W>T"
\|endif
augroup END
" Clear trailing whitespace when saving vimrc.
augroup TrimWhitespace
autocmd!
autocmd BufWritePre *vimrc :%s/\s\+$//e
augroup END
" Restore the last cursor position when opening a file.
" https://vimhelp.org/usr_05.txt.html#last-position-jump
augroup RestoreCursorPosition
autocmd!
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup END
" Automatically activate some filetypes.
augroup FileTypes
autocmd!
autocmd BufRead,BufNewFile .bashrc,.bash_profile set filetype=bash
autocmd BufRead,BufNewFile * if getline(1) == '#!/bin/bash' || getline(1) == '#!/usr/bin/env bash' | set filetype=bash | endif
autocmd BufRead,BufNewFile Dockerfile* set filetype=dockerfile
autocmd BufRead,BufNewFile .gitconfig* set filetype=gitconfig
autocmd BufRead,BufNewFile *.jsx set filetype=javascriptreact
autocmd BufRead,BufNewFile *.tfstate set filetype=json
autocmd BufRead,BufNewFile tsconfig*.json set filetype=jsonc
autocmd BufRead,BufNewFile .env*,env,bookmarks set filetype=sh
autocmd BufRead,BufNewFile poetry.lock set filetype=toml
autocmd BufRead,BufNewFile *.tsx set filetype=typescriptreact
augroup END
" Toggle syntax highlighting together with diff mode.
augroup DiffSettings
autocmd!
autocmd DiffUpdated * if &diff
\| syntax off
\| else
\| syntax enable
\| endif
augroup END
let PostLaunchSettings = NewPostLaunchSettings(PathToSpellFolder)
augroup SetPostLaunchSettings
autocmd!
autocmd VimEnter * call PostLaunchSettings.f()
augroup END