-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.vim
executable file
·1847 lines (1630 loc) · 62.1 KB
/
init.vim
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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
set nocompatible
let mapleader = "\<Space>"
let maplocalleader = ","
if &shell =~# 'fish$'
set shell=/bin/bash
endif
" A path to Python interpreter required for some plugins.
" On Windows you should add python.exe to your system-level PATH to make it work.
" And do: pip install neovim.
" if !has('win32')
" let g:python3_host_prog = '/usr/bin/python3.10'
" else
" let g:python3_host_prog = '\Users\<>\AppData\Local\Programs\Python\Python39\python.exe'
" endif
" We have to tweak PATH on Windows to make *nix tools from git-bash work.
if has('win32')
let $PATH = "C:\\Program Files\\Git\\usr\\bin;" . $PATH
endif
" {{{ Plugins
call plug#begin('~/.local/share/nvim/plugged')
Plug 'kshenoy/vim-signature' " Extended marks support
Plug 'tpope/vim-eunuch' " Helpers for Shell
Plug 'tpope/vim-repeat' " Remap . in a way that plugins can tap into it
Plug 'andymass/vim-matchup' " Better %
Plug 'junegunn/vim-easy-align' " A Vim alignment plugin
Plug 'tpope/vim-surround' " Surround text w/ brackets
Plug 'tpope/vim-abolish' " Case-sensitive search/substitute/abbreviate
Plug 'jiangmiao/auto-pairs' " Insert or delete brackets, parens, quotes in pair
Plug 'tpope/vim-rsi' " Readline (emacs) keybindings in command and insert modes
Plug 'osyo-manga/vim-over' " :substitute preview
Plug 'christoomey/vim-tmux-navigator' " tmux integration
Plug 'tyru/open-browser.vim' " Plugin for openning links in the browser
Plug 'itchyny/lightline.vim' " Statusline plugin
Plug 'jubnzv/gruvbox' " Color scheme
Plug 'norcalli/nvim-colorizer.lua' " Colorize color names and codes
Plug 'haya14busa/incsearch.vim' " Incrementally highlight search results
Plug 'itchyny/vim-cursorword' " Plugin to highlight the word under the cursor
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'cohama/agit.vim' " gitk clone for vim
Plug 'airblade/vim-gitgutter' " Shows git status on a gutter column
Plug 'ruifm/gitlinker.nvim' " Generate shareable links for git frontends
Plug 'statox/vim-compare-lines' " Compares symbol in two lines in the buffer
Plug 'kyazdani42/nvim-tree.lua' " A tree explorer plugin for vim
Plug 'kyazdani42/nvim-web-devicons' " devicons for nvim-tree.lua
Plug 'mbbill/undotree' " Emacs' undotree
Plug 'rhysd/git-messenger.vim' " Reveal the commit messages under the cursor
Plug 'simrat39/symbols-outline.nvim' " Viewer & Finder for LSP symbols and tags
Plug 'ludovicchabant/vim-gutentags' " Auto (re)generate tag files
Plug 'terryma/vim-expand-region' " Visually select increasingly larger regions of text
Plug 'machakann/vim-swap' " Reorder arguments in functions with `g>` and `g<`
Plug 'numToStr/Comment.nvim' " Comment plugin
Plug 'Shougo/deoplete.nvim', {
\ 'do': ':UpdateRemotePlugins' } " Autocomplition
Plug 'sirver/ultisnips' " Snippets plugin
Plug 'honza/vim-snippets' " A collection of snippets
Plug 'lukas-reineke/indent-blankline.nvim' " Display indent levels in code
Plug 'neovim/nvim-lspconfig' " Configuration for native Neovim LSP client
Plug 'j-hui/fidget.nvim', {
\ 'tag': 'legacy' } " UI that shows LSP progress for supported LSP servers
Plug 'jubnzv/virtual-types.nvim' " Plugin that shows type annotations in virtual text
Plug 'Shougo/deoplete-lsp' " Neovim's LSP Completion source for deoplete
Plug 'sbdchd/neoformat' " Integration with code formatters
Plug 'jpalardy/vim-slime' " REPL integraion
Plug 'derekwyatt/vim-fswitch' " This Vim plugin will help switching between companion files
Plug 'luochen1990/rainbow' " Rainbow Parentheses improved
Plug 'dhruvasagar/vim-table-mode', {
\ 'for': ['markdown'] } " VIM Table Mode for instant table creation
Plug 'tpope/vim-markdown', {
\ 'for': ['markdown'] } " Extra settings for markdown
Plug 'masukomi/vim-markdown-folding', {
\ 'for': ['markdown'] } " Markdown folding by sections
Plug 'iamcco/markdown-preview.nvim', {
\ 'for': ['markdown'],
\ 'do': { -> mkdp#util#install() },
\ 'tag': 'v0.0.10' } " Live markdown preview in the browser
Plug 'junegunn/goyo.vim' " Distraction-free writing
Plug 'preservim/vim-pencil' " Soft-wraps in markdown
Plug 'nvim-lua/plenary.nvim' " Various utilities used by other plugins
Plug 'nvim-telescope/telescope.nvim' " Fuzzy-finder
Plug 'folke/trouble.nvim' " Show persistent telescope results
Plug 'stevearc/dressing.nvim' " A plugin that replaces most of built-in menus with telescope
Plug 'nvim-treesitter/nvim-treesitter' " tree-sitter integration
Plug 'nvim-treesitter/nvim-treesitter-context' " Shows context of a current funciton using treesitter
Plug 'nvim-orgmode/orgmode.nvim' " org-mode clone
Plug 'jamessan/vim-gnupg' " Transparent editing of GPG-encrypted files
Plug 'lervag/vimtex', { 'for': ['tex'] } " LaTeX plugin
Plug 'bfrg/vim-cpp-modern', {
\ 'for': ['cpp'] } " Extended Vim syntax highlighting for C and C++ (C++11/14/17/20)
Plug 'ocaml/vim-ocaml', {
\ 'for': ['ocaml'] } " Vim runtime files for OCaml
Plug 'vim-python/python-syntax', {
\ 'for': ['python'] } " Extended python syntax
Plug 'wlangstroth/vim-racket', {
\ 'for': ['rkt'] } " Racket syntax highlight
Plug 'rust-lang/rust.vim', {
\ 'for': ['rust'] } " Rust plugin
Plug 'fatih/vim-go', { 'for': ['go'] } " (bloated) golang environment
Plug 'tomlion/vim-solidity', {
\ 'for': ['sol'] } " Solidity syntax highlight
Plug 'leafgarland/typescript-vim', {
\ 'for': ['typescript'] } " Typescript syntax highlight
Plug 'othree/xml.vim', {
\ 'for': ['xml', 'html'] } " More convient working w/ html and xml tags
Plug 'whonore/Coqtail', { 'for': ['coq'] } " Coq plugin
Plug 'florentc/vim-tla', {
\ 'for': ['tla'] } " TLA+ plugin
Plug 'hanw/vim-bluespec', {
\ 'for': ['quint'] } " Bluespec mode, good for quint
Plug 'tikhomirov/vim-glsl', {
\ 'for': ['glsl'] } " GLSL mode
Plug 'elzr/vim-json', {'for': ['json'] }
" LLVM plugin
" See: https://github.com/llvm/llvm-project/tree/master/llvm/utils/vim
if isdirectory('/home/jubnzv/Sources/llvm-project/llvm/utils/vim/')
Plug '/home/jubnzv/Sources/llvm-project/llvm/utils/vim/'
endif
if isdirectory('/home/jubnzv/Dev/scilla.nvim/')
Plug '/home/jubnzv/Dev/scilla.nvim/'
else
Plug 'jubnzv/vim-scilla', { 'for': ['scilla'] }
endif
call plug#end()
" }}}
" {{{ Disable some builtin plugins
let g:loaded_gzip = 1
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
let g:loaded_zipPlugin = 1
let g:loaded_2html_plugin = 1
" }}}
" {{{ General options
set viminfo='1000,f1 " Save global marks for up to 1000 files
set scrolloff=7 " 7 lines above/below cursor when scrolling
set scroll=7 " Number of lines scrolled by <C-u> and <C-d>
set undofile
set undodir=$HOME/.vim/undo
set undolevels=1000
set undoreload=10000
set clipboard=unnamedplus,unnamed " Use system clipboard
set showmatch " Show matching brackets when text indicator is over them
set mat=1 " How many tenths of a second to blink when matching brackets
set wildmenu " wildmenu: command line completion
set wildmode=longest,list,full
set wildignore+=*.o " Compiled object files
set wildignore+=*.pyc " Python bytecode
set wildignore+=*.aux,*.out,*.toc " LaTeX output
set wildignore+=*.jpg,*.jpeg,*.gif,*.png " Binary images
set wildignore+=.hg,.git,.svn " VCS
set wildignore+=*~ " Backup files
set wildcharm=<C-z>
set timeoutlen=500 " Time to wait for a mapped sequence to complete (ms)
set notimeout " Remove delay between complex keybindings.
set noautochdir " Set working directory to the current file
set autoindent " Autoindent when starting new line, or using o or O.
set noautoread " Don't reload unchanged files automatically.
set hidden
set tabstop=4
set shiftwidth=4
set expandtab " On pressing tab insert 4 spaces
set lazyredraw " Do not redraw screen in the middle of a macro. Makes them complete faster.
set nojoinspaces " Don't add two spaces when joining a line that ends with.,?, or !
set eol
set fixeol " <EOL> at the end of file will be restored if missing
set mouse=a
" Disable syntax highlighting for large files
au BufWinEnter * if line2byte(line("$") + 1) > 1000000 | syntax clear | endif
" Disable spellchecking globally, because it works incorrectly for the most of filetypes.
set nospell
" Default conceal settings
set conceallevel=0
set concealcursor=nc
" Cyrillic layout in normal mode
set langmap+=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ
set langmap+=фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
set langmap+=ЖжЭэХхЪъ;\:\;\"\'{[}]
" Allows to open files in external program with `gx` inside netrw
let g:netrw_browsex_viewer = "xdg-open"
" }}}
" {{{ UI options
set termguicolors
set winblend=5 " Transparency for floating windows
set pumblend=5 " Transparency for popup menus
set guioptions-=m " Remove menu bar
set guioptions-=T " Remove toolbar
set guioptions-=r " Remove right-hand scroll bar
set guioptions-=L " Remove left-hand scroll bar
set shortmess+=Ic " Don't display the intro message on starting vim
set noshowmode
set relativenumber
set cursorline
set laststatus=2 " Always show status line
set title " Show window title
set signcolumn=yes
set background=dark
set t_Co=256 " 256-colors mode
set guicursor+=c-ci-cr:block " Cursor style
" Italic symbols in terminal
set t_ZH=^[[3m
set t_ZR=^[[23m
" Gruvbox configuration
let g:gruvbox_sign_column='bg0'
let g:gruvbox_color_column='bg1'
let g:gruvbox_number_column='bg0'
let g:gruvbox_italic=0
colorscheme gruvbox
" Highlighting
highlight Todo ctermfg=130 guibg=#af3a03
" }}}
" {{{ Setup neovim-qt
if (has('nvim') && len(nvim_list_uis()) > 0 && (!nvim_list_uis()[0]['ext_termcolors'] == 1))
if has('win32')
set guifont=JetBrainsMono\ NF:h11
else
" set guifont=JetBrainsMono\ NF\ \[JB\]:h11
endif
nnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>
inoremap <silent><RightMouse> <Esc>:call GuiShowContextMenu()<CR>
vnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>
" toggleterm
nnoremap <silent>`" <Cmd>exe v:count1 . "ToggleTerm"<CR>
nnoremap <silent>`% <Cmd>exe v:count1 . "ToggleTerm direction=vertical size=50"<CR>
nnoremap <silent>`t :call system('kitty -e '.shellescape(getcwd()).' &')<CR>
endif
" }}}
" {{{ Common functions and commands
" Don't parse modelines on temporary paths (google: "vim modeline vulnerability").
function! ParseModeline()
let l:path = expand('%:p')
if l:path =~ '/tmp' || l:path =~ '~/Downloads'
setlocal nomodeline
endif
endfunction
au! BufReadPost,BufNewFile * call ParseModeline()
" Jump to the last position when reopening a file (see `/etc/vim/vimrc` on Debian)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" }}}
" {{{ Keybindings
" {{{ Common
inoremap jj <Esc>
nnoremap <leader>h :noh<CR>
nnoremap <leader>xc :q<CR>
nnoremap <leader>w :w<CR>
cabbrev w1 w!
" Y yanks from the cursor to the end of line as expected. See :help Y.
nnoremap Y y$
" Replace-paste without yanking deleted lines
" nnoremap <leader>y "0y
" nnoremap <leader>p "0p
" Insert newline without entering insert mode
" nmap zj o<Esc>k
" nmap zk O<Esc>j
" Map Ctrl-Backspace to delete previous word or selected region
inoremap <C-BS> <C-W>
cnoremap <C-BS> <C-W>
" Reload vimrc
nnoremap <localleader>R :so $MYVIMRC<CR>:echo "Config reloaded"<CR>
" Killing local buffer without losing split
:command! Bc sb # | bd #
" Disable the ever-annoying Ex mode shortcut key
nnoremap Q @@
" Navigate to errors list
" NOTE: Use LSP mappings instead
" nnoremap ]e :cnext <CR>
" nnoremap [e :cprevious<CR>
" Search visually selected text
vnoremap // y/<C-R>"<CR>
" Search in visal selected area
vnoremap <M-/> <Esc>/\%V
" Keep selected text selected when fixing indentation
vnoremap < <gv
vnoremap > >gv
" Fix common typos
:command! W w
:command! Q q
:command! E e
" E45: 'readonly' option is set (add ! to override)
" Does not work on neovim because job-control differs.
" See:
" https://github.com/neovim/neovim/issues/8217
" https://github.com/neovim/neovim/issues/1716#issuecomment-454519716
" https://github.com/neovim/neovim/pull/8389
" cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
" Use 'lambdalisue/suda.vim' as workaround
let g:suda#prefix = 'sudo://'
cnoremap e!! execute 'edit! sudo://%'
cnoremap w!! execute 'write sudo://% <bar> edit! sudo://%'
" Command to manually create directory for current file
function! WriteCreatingDirs()
execute ':silent !mkdir -p %:h'
endfunction
command! Mkw call WriteCreatingDirs()
" Create directories before write
" [1]: https://stackoverflow.com/questions/4292733/vim-creating-parent-directories-on-save
augroup BWCCreateDir
au!
au BufWritePre * if expand("<afile>")!~#'^\w\+:/' && !isdirectory(expand("%:h")) | execute "silent! !mkdir -p ".shellescape(expand('%:h'), 1) | redraw! | endif
augroup END
" Remove the Windows ^M - when the encodings gets messed up
noremap <leader>rm mmHmt:%s/<C-V><CR>//ge<cr>'tzt'm
" }}}
" Editing neighbors
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
map <leader>ew :e %%
map <leader>ee :e
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
map <leader>ec :cd %%<cr>
map <leader>eC :cd ..<cr>
" Tabs management
nnoremap <A-t> :tabnew<CR>
inoremap <A-t> <C-O>:tabnew<CR>
nnoremap <A-Tab> :tabnext<CR>
inoremap <A-Tab> <C-O>:tabnext<CR>
nnoremap <A-1> 1gt
inoremap <A-1> <C-O>1gt
nnoremap <A-2> 2gt
inoremap <A-2> <C-O>2gt
nnoremap <A-3> 3gt
inoremap <A-3> <C-O>3gt
nnoremap <A-4> 4gt
inoremap <A-4> <C-O>4gt
nnoremap <A-5> 5gt
inoremap <A-5> <C-O>5gt
nnoremap <A-6> 6gt
inoremap <A-6> <C-O>6gt
nnoremap <A-7> 7gt
inoremap <A-7> <C-O>7gt
nnoremap <A-8> 8gt
inoremap <A-8> <C-O>8gt
nnoremap <A-9> 9gt
inoremap <A-9> <C-O>9gt
" Refresh content of the current buffer
nnoremap <silent> <leader>B :checktime<CR>
" Convert the ^M linebreaks to the normal linebreaks
nnoremap <silent> <leader>rl :set ff=unix<CR> :e ++ff=dos<CR>
" EOL format
menu EOL.unix :set fileformat=unix<CR>
menu EOL.dos :set fileformat=dos<CR>
menu EOL.mac :set fileformat=mac<CR>
" Change encoding
menu EEnc.cp1251 :e ++enc=cp1251<CR>
menu EEnc.koi8-r :e ++enc=koi8-r<CR>
menu EEnc.cp866 :e ++enc=ibm866<CR>
menu EEnc.utf-8 :e ++enc=utf-8<CR>
menu EEnc.ucs-2le :e ++enc=ucs-2le<CR>
" Convert file encoding
menu FEnc.cp1251 :set fenc=cp1251<CR>
menu FEnc.koi8-r :set fenc=koi8-r<CR>
menu FEnc.cp866 :set fenc=ibm866<CR>
menu FEnc.utf-8 :set fenc=utf-8<CR>
menu FEnc.ucs-2le :set fenc=ucs-2le<CR>
" Remove all trailing whitespaces
nnoremap <silent> <leader>rs :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>
" ё -> е
nnoremap <silent> <leader>r` :%s/ё/е/g<cr>
" Find all cyrillic characters
nnoremap <silent> <leader>/c /[\d1040-\d1103]<cr>
" Re-select the text you just pasted
nnoremap gp `[v`]
" Switch to the recent buffer
nnoremap <A-r> <C-^>
" Use Ctrl-W operation in insert mode
inoremap <C-w> <C-g>u<C-w>
" {{{ Copy file path to the system clipboard
if has('win32')
nmap <silent> <leader>cr :let @+=substitute(expand("%"), "/", "\\", "g")<CR>:echo "Copied: " . expand("%")<CR>
nmap <silent> <leader>ca :let @+=substitute(expand("%:p"), "/", "\\", "g")<CR>:echo "Copied: " . expand("%:p")<CR>
else
nmap <silent> <leader>cr :let @+=expand("%")<CR>:echo "Copied: " . expand("%")<CR>
nmap <silent> <leader>ca :let @+=expand("%:p")<CR>:echo "Copied: " . expand("%:p")<CR>
endif
" }}}
" {{{ gF with column support
function! GoToColumnInFile (fileInfoString)
let fileInfo = split(a:fileInfoString, ":")
let column = 0
normal! gF
if len(fileInfo) > 2
" Cut trailing `"`
let column = split(fileInfo[2], "\"")[0]
echo column
execute 'normal! ' . column . '|'
endif
endfunction
nnoremap <localleader>f :call GoToColumnInFile(expand("<cWORD>"))<CR>
" }}}
" Highlight search results incrementally (haya14busa/incsearch.vim)
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
" vim-easyalign
cnoreabbrev Tab EasyAlign
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" }}}
" {{{ Lightline
let g:buftabline_indicators=1 " show modified
let g:lightline = {
\ 'colorscheme': 'gruvbox',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ],
\ [ 'current_function'] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ],
\ [ 'gitbranch' ] ],
\ },
\ 'component_expand': {
\ 'lsp_warnings': 'LightlineLspWarnings',
\ 'lsp_errors': 'LightlineLspErrors',
\ },
\ 'component_function': {
\ 'filename': 'LightlineStrippedFilename',
\ 'gitbranch': 'FugitiveHead'
\ },
\ 'component_type': {
\ 'lsp_warnings': 'warning',
\ 'lsp_errors': 'error',
\ 'readonly': 'error',
\ },
\ }
function! LightlineLspWarnings() abort
let sl = ''
if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
let warnings = luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Warning]])")
return warnings.' ◆'
else
return ''
endif
return sl
endfunction
function! LightlineLspErrors() abort
let sl = ''
if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
let errors = luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Error]])")
return errors.' ✕'
else
return ''
endif
return sl
endfunction
function! LightlineStrippedFilename() abort
let subs = split(expand('%'), "/")
" Handle './filename' and 'filename' cases
let subs_len = len(subs)
if subs_len < 3
if subs_len == 1
return subs[0]
endif
if (subs_len == 2) && (subs[0] == '.')
return subs[1]
endif
endif
let name = ""
let i = 1
for s in subs
let parent = name
if i == len(subs)
let name = parent . '/' . s
elseif i == 1
let name = parent . strpart(s, 0, 2)
else
let name = parent . '/' . strpart(s, 0, 2)
endif
let i += 1
endfor
return name
endfunction
" }}}
" {{{ Web-browser integration (tyru/open-browser.vim)
let g:openbrowser_search_engines = extend(
\ get(g:, 'openbrowser_search_engines', {}),
\ {
\ 'github': 'http://github.com/search?q={query}',
\ 'github-c': 'http://github.com/search?l=C&q=language%3AC+{query}&type=Code',
\ 'github-cpp': 'http://github.com/search?l=C%2B%2B&q=language%3AC%2B%2B+{query}&type=Code',
\ 'github-python': 'http://github.com/search?l=Python&q=language%3APython+{query}&type=Code',
\ 'github-rust': 'http://github.com/search?l=Rust&q=language%3ARust+{query}&type=Code',
\ 'github-go': 'http://github.com/search?l=Go&q=language%3AGo+{query}&type=Code',
\ 'github-ocaml': 'http://github.com/search?l=OCaml&q=language%3AOCaml+{query}&type=Code',
\ 'github-vimscript': 'http://github.com/search?l=Vim+Script&language%3Avimscript+{query}&type=Code',
\ 'grep-app': 'https://grep.app/search?q={query}&case=true',
\ 'google': 'http://google.com/search?q={query}',
\ 'yandex-translate-en-ru': 'https://translate.yandex.ru/?lang=en-ru&text={query}',
\ 'ludwig-en': 'https://ludwig.guru/ru/s/{query}',
\ 'debian-code-search': 'https://codesearch.debian.net/search?q={query}',
\ 'cppreference': 'https://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search={query}',
\ 'hotexamples': 'https://cpp.hotexamples.com/search/{query}',
\ 'qt': 'https://doc.qt.io/qt-5/search-results.html?q={query}',
\ 'python': 'http://docs.python.org/dev/search.html?q={query}&check_keywords=yes&area=default',
\ },
\ 'keep'
\)
let g:openbrowser_default_search = 'google'
function! s:JbzGetVisual()
let l:old_reg = getreg('"')
let l:old_regtype = getregtype('"')
norm gvy
let l:ret = getreg('"')
call setreg('"', l:old_reg, l:old_regtype)
exe "norm \<Esc>"
return substitute(l:ret, '\n\+$', '', '') " chomp
endfunction
function! s:JbzSetOpenbrowserBindings(keybind, name)
silent! exe 'nnoremap <silent> ' . a:keybind . " :call openbrowser#smart_search(expand('<cword>'), " . '"' . a:name . '")<CR>'
silent! exe 'vnoremap <silent> ' . a:keybind . ' :<C-U>execute "call openbrowser#smart_search(\"" . <SID>JbzGetVisual() . "\", \"' . a:name . '\")"<CR>'
endfunction
nnoremap <silent> <leader>os <Plug>(openbrowser-smart-search)
call s:JbzSetOpenbrowserBindings("<leader>osg", "google")
call s:JbzSetOpenbrowserBindings("<leader>otr", "yandex-translate-en-ru")
call s:JbzSetOpenbrowserBindings("<leader>otl", "ludwig-en")
call s:JbzSetOpenbrowserBindings("<leader>ogs", "github")
call s:JbzSetOpenbrowserBindings("<leader>ogc", "github-c")
call s:JbzSetOpenbrowserBindings("<leader>ogx", "github-cpp")
call s:JbzSetOpenbrowserBindings("<leader>ogp", "github-python")
call s:JbzSetOpenbrowserBindings("<leader>ogr", "github-rust")
call s:JbzSetOpenbrowserBindings("<leader>ogg", "github-go")
call s:JbzSetOpenbrowserBindings("<leader>ogo", "github-ocaml")
call s:JbzSetOpenbrowserBindings("<leader>ogv", "github-vimscript")
call s:JbzSetOpenbrowserBindings("<leader>osa", "grep-app")
call s:JbzSetOpenbrowserBindings("<leader>osh", "hotexamples")
call s:JbzSetOpenbrowserBindings("<leader>osx", "cppreference")
call s:JbzSetOpenbrowserBindings("<leader>osq", "qt")
call s:JbzSetOpenbrowserBindings("<leader>osp", "python")
" }}}
" {{{ tmux and vim-slime configuration
" Free my prefix key
map ` <Nop>
if exists('$TMUX')
" Execute previous command in the last active pane
nnoremap <silent> <leader><tab> :silent !tmux send-keys -t \! Up Enter<cr>
nnoremap <silent> <leader><leader><tab> :silent !tmux clear-history -t right && tmux send-keys -t \! C-l Up Enter<cr>
endif
" slime
let g:slime_target = "tmux"
let g:slime_paste_file = tempname()
let g:slime_default_config = {"socket_name": "default", "target_pane": "1.2"}
let g:slime_dont_ask_default = 1
let g:slime_no_mappings = 1
" Configure slime for the right tmux pane in the current window
function! s:JbzSlimeRight()
if !exists('$TMUX')
echo "tmux is not running"
return
endif
let win_num = split(system("tmux display-message -p '#I'"), "\n")[0]
let sock = split($TMUX, ",")[0]
let b:slime_config = {"socket_name": sock, "target_pane": win_num . '.2' }
call slime#config()
endfunction
command! JbzSlimeRight call s:JbzSlimeRight()
" Open tmux pane with selected REPL and run slime configuration routine
function! s:JbzOpenSlimeREPL(repl_exe, ...)
if !exists('$TMUX')
echo "tmux is not running"
return
endif
let cmd = a:repl_exe
" Parse additional command to execute before running the REPL
let cmd_aux = get(a:, 1, "")
if !empty(cmd_aux) | let cmd = cmd_aux . " && " . cmd | endif
call system("tmux split-window -h \"" . cmd . "\"")
call system("tmux last-pane")
echoerr "cmd=" . cmd
call s:JbzSlimeRight()
endfunction
command! -nargs=+ JbzOpenSlimeREPL call s:JbzOpenSlimeREPL(<f-args>)
nnoremap <leader>sc :JbzSlimeRight
xmap <leader>ss <Plug>SlimeRegionSend
nmap <leader>ss <Plug>SlimeParagraphSend
nmap <leader>sl <Plug>SlimeLineSend
" }}}
" {{{ Parens settings
let g:AutoPairsShortcutToggle = ''
" Free statusline from Matchup
let g:matchup_matchparen_status_offscreen=0
" Insert fold block
" let g:surround_102 = split(&commentstring, '%s')[0] . " {{{ \r " . split(&commentstring, '%s')[0] . " }}}"
" }}}
" {{{ Folding settings
set foldmethod=syntax
set foldnestmax=6
set nofoldenable " Disable folding when openning a file
set foldlevel=2
set foldcolumn=0
set fillchars=fold:\
" {{{ Custom fold function
" http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/
function! CustomFoldText()
let fs = v:foldstart
while getline(fs) =~ '^\s*$' | let fs = nextnonblank(fs + 1)
endwhile
if fs > v:foldend
let line = getline(v:foldstart)
else
let line = substitute(getline(fs), '\t', repeat(' ', &tabstop), 'g')
endif
let w = &l:textwidth - 3 - &foldcolumn - (&number ? 8 : 0)
let foldSize = 1 + v:foldend - v:foldstart
let foldLevelStr = "" . string(v:foldlevel)
let lineCount = line("$")
let foldSizeStr = printf("[%4dL|%4.1f%%]", foldSize, (foldSize*1.0)/lineCount*100)
let expansionString = " " . repeat(" ", w - strwidth(foldSizeStr.line.foldLevelStr))
return line . expansionString . foldLevelStr . " " . foldSizeStr
endf
set foldtext=CustomFoldText()
" }}}
" }}}
" {{{ Highlight specific lines
highlight LineHighlight ctermbg=darkgray guibg=#458588
nnoremap <silent><leader>m :call matchadd('LineHighlight', '\%'.line('.').'l')<cr>
nnoremap <silent><leader>M :call clearmatches()<cr>
" }}}
" {{{ UndoTree
nnoremap <A-U> :UndotreeToggle<cr>
" }}}
" {{{ DirDiff
let g:DirDiffWindowSize = 6
let g:DirDiffEnableMappings = 0
let g:DirDiffExcludes = "CVS,*.class,*.exe,.*.swp,*.pyc,tags"
" }}}
" {{{ Datetime
" language time C
nnoremap <silent> <leader>c. "=strftime("%Y-%m-%d")<CR>P
nnoremap <silent> <C-c>. "=strftime("%Y-%m-%d")<CR>P
inoremap <silent> <C-c>. <C-R>=strftime("%Y-%m-%d")<CR>
" If buffer modified, update any 'Last modified: ' in the first 20 lines.
" 'Last modified: ' can have up to 10 characters before (they are retained).
" Restores cursor and window position using save_cursor variable.
function! LastModified()
if &modified
let save_cursor = getpos(".")
let n = min([20, line("$")])
keepjumps exe '1,' . n . 's#^\(.\{,10}Last modified: \).*#\1' .
\ strftime('%a %b %d, %Y %I:%M%p') . '#e'
call histdel('search', -1)
call setpos('.', save_cursor)
endif
endfun
au BufWritePre * call LastModified()
" }}}
" {{{ Comment.nvim
lua << EOF
require('Comment').setup()
--vim.keymap.set('x', 'gc', '<Plug>(comment_toggle_linewise_visual)')
EOF
if has('win32')
nmap <C-/> gcc<Space>
vmap <C-/> <Plug>(comment_toggle_linewise_visual)
else
nmap <C-_> gcc
vmap <C-_> <Plug>(comment_toggle_linewise_visual)
endif
" }}}
" {{{ indent-blankline.nvim
lua << EOF
require("ibl").setup()
EOF
" }}}
" {{{ 80+ characters line highlight
function! s:SetColorColumn()
if &textwidth == 0
setlocal colorcolumn=80
else
setlocal colorcolumn=+0
endif
endfunction
augroup colorcolumn
au!
au OptionSet textwidth call s:SetColorColumn()
au BufEnter * call s:SetColorColumn()
augroup end
" }}}
" {{{ Trailing whitespaces
" http://vim.wikia.com/wiki/Highlight_unwanted_spaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
au BufWinEnter * match ExtraWhitespace /\s\+$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhitespace /\s\+$/
au BufWinLeave * call clearmatches()
" }}}
" {{{ ctags
set tags=./tags;
let g:gutentags_ctags_exclude = [
\'node_modules', '_build', 'build', 'CMakeFiles', '.mypy_cache', 'venv',
\'*.md', '*.tex', '*.css', '*.html', '*.json', '*.xml', '*.xmls', '*.ui']
" Guttentags will exclude files from wildignore settings
let g:gutentags_ctags_exclude_wildignore = 1
" }}}
" {{{ vim-signature
let g:SignatureMap = {
\ 'Leader' : "m",
\ 'PlaceNextMark' : "m,",
\ 'ToggleMarkAtLine' : "m.",
\ 'PurgeMarksAtLine' : "m-",
\ 'DeleteMark' : "dm",
\ 'PurgeMarks' : "m<Space>",
\ 'PurgeMarkers' : "m<BS>",
\ 'GotoNextLineAlpha' : "']",
\ 'GotoPrevLineAlpha' : "'[",
\ 'GotoNextSpotAlpha' : "`]",
\ 'GotoPrevSpotAlpha' : "`[",
\ 'GotoNextLineByPos' : "]'",
\ 'GotoPrevLineByPos' : "['",
\ 'GotoNextSpotByPos' : "]`",
\ 'GotoPrevSpotByPos' : "[`",
\ 'GotoNextMarker' : "]-",
\ 'GotoPrevMarker' : "[-",
\ 'GotoNextMarkerAny' : "]=",
\ 'GotoPrevMarkerAny' : "[=",
\ 'ListBufferMarks' : "m/",
\ 'ListBufferMarkers' : "m?"
\ }
nnoremap <silent> [1 :call signature#marker#Goto('prev', 1, v:count)<cr>
nnoremap <silent> ]1 :call signature#marker#Goto('next', 1, v:count)<cr>
nnoremap <silent> [2 :call signature#marker#Goto('prev', 2, v:count)<cr>
nnoremap <silent> ]2 :call signature#marker#Goto('next', 2, v:count)<cr>
nnoremap <silent> [3 :call signature#marker#Goto('prev', 3, v:count)<cr>
nnoremap <silent> ]3 :call signature#marker#Goto('next', 3, v:count)<cr>
nnoremap <silent> [4 :call signature#marker#Goto('prev', 4, v:count)<cr>
nnoremap <silent> ]4 :call signature#marker#Goto('next', 4, v:count)<cr>
nnoremap <silent> [5 :call signature#marker#Goto('prev', 5, v:count)<cr>
nnoremap <silent> ]5 :call signature#marker#Goto('next', 5, v:count)<cr>
nnoremap <silent> [6 :call signature#marker#Goto('prev', 6, v:count)<cr>
nnoremap <silent> ]6 :call signature#marker#Goto('next', 6, v:count)<cr>
nnoremap <silent> [7 :call signature#marker#Goto('prev', 7, v:count)<cr>
nnoremap <silent> ]7 :call signature#marker#Goto('next', 7, v:count)<cr>
nnoremap <silent> [8 :call signature#marker#Goto('prev', 8, v:count)<cr>
nnoremap <silent> ]8 :call signature#marker#Goto('next', 8, v:count)<cr>
nnoremap <silent> [9 :call signature#marker#Goto('prev', 9, v:count)<cr>
nnoremap <silent> ]9 :call signature#marker#Goto('next', 9, v:count)<cr>
" }}}
" {{{ deoplete
let g:deoplete#enable_at_startup = 1
inoremap <expr><A-q> pumvisible() ? deoplete#mappings#close_popup() : "\<CR>"
inoremap <expr><A-j> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr><A-k> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr><A-l> pumvisible() ? "\<CR>" : ""
inoremap <expr><A-o> deoplete#mappings#manual_complete()
" Otherwise autocompletion in Telescope writes to files when typing <Enter>.
autocmd FileType TelescopePrompt call deoplete#custom#buffer_option('auto_complete', v:false)
call deoplete#custom#source('_',
\ 'matchers', ['matcher_full_fuzzy'])
set completeopt-=preview
" Add Icons for LSP_KINDS.
" See: https://github.com/deoplete-plugins/deoplete-lsp/pull/46/files
let g:deoplete#lsp#use_icons_for_candidates = 1
" }}}
" {{{ UltiSnips
let g:UltiSnipsExpandTrigger='<A-l>'
let g:UltiSnipsJumpForwardTrigger='<A-l>'
let g:UltiSnipsJumpBackwardTrigger='<A-h>'
nnoremap <localleader>sr :call UltiSnips#RefreshSnippets()<cr>:echo "Snippets reloaded"<CR>
nnoremap <localleader>se :UltiSnipsEdit<CR>
" }}}
" {{{ neoformat
nnoremap <leader>lf :Neoformat<CR>
" Enable for debugging
" let g:neoformat_verbose = 1
let g:neoformat_enabled_html = ['prettier']
let g:neoformat_enabled_css = ['prettier']
let g:neoformat_enabled_java = ['astyle']
let g:neoformat_enabled_python = ['autopep8']
" let g:neoformat_enabled_ocaml = ['ocpindent']
let g:neoformat_enabled_ocaml = ['ocamlformat']
let g:neoformat_enabled_lua = ['stylua']
let g:neoformat_enabled_haskell = ['ormolu']
let g:neoformat_enabled_scilla = ['scilla_fmt']
" }}}
" {{{ EditorConfig
let g:EditorConfig_exclude_patterns = ['fugitive://.\*', 'scp://.\*']
" }}}
" {{{ FSwitch bindings
nnoremap <silent> <A-o> :FSHere<cr>
nnoremap <silent> <localleader>oh :FSSplitLeft<cr>
nnoremap <silent> <localleader>oj :FSSplitBelow<cr>
nnoremap <silent> <localleader>ok :FSSplitAbove<cr>
nnoremap <silent> <localleader>ol :FSSplitRight<cr>
" }}}
" {{{ Git
let g:gitgutter_override_sign_column_highlight = 0
let g:gitgutter_map_keys = 0
nmap [v <Plug>(GitGutTerPrevHunk)
nmap ]v <Plug>(GitGutterNextHunk)
nmap <leader>v- <Plug>(GitGutterStageHunk)
nmap <leader>v_ <Plug>(GitGutterUndoHunk)
nmap <leader>vr <Plug>(GitGutterRefresh)
nmap <localleader>v <Plug>(GitGutterPreviewHunk)
nmap <localleader>b <Plug>(git-messenger)
nmap <localleader>vs :Git<cr>
nmap <localleader>vD :Git! diff<cr>
nmap <localleader>vb :Git blame<cr>
nmap <localleader>vf :GFiles<cr>
nmap <localleader>vl :Agit<cr>
" Copy a shareable link to git frontend
lua << EOF
require"gitlinker".setup()
vim.api.nvim_set_keymap('n', '<leader>vo',
'<cmd>lua require"gitlinker".get_buf_range_url("n", {action_callback = require"gitlinker.actions".open_in_browser})<cr>', {})
vim.api.nvim_set_keymap('v', '<leader>vo',
'<cmd>lua require"gitlinker".get_buf_range_url("v", {action_callback = require"gitlinker.actions".open_in_browser})<cr>', {})
EOF
" }}}
" {{{ table-mode
let g:table_mode_map_prefix = ',t'
let g:table_mode_delete_row_map = ',tdd'
let g:table_mode_delete_column_map = ',tdc'
" }}}
" {{{ Plain text editing
let s:PTModeActive = exists('w:PTModeActive') ? w:PTModeActive : 0
function! s:PTEnable()
let s:PTModeActive = 1
Pencil
Goyo
:silent! call matchadd('MdTodo', 'TODO', -1)<CR>
endfunction
function! s:PTDisable()
let s:PTModeActive = 0
NoPencil
Goyo!
endfunction
function! s:PTToggle()
if s:PTModeActive
call s:PTDisable()
else
call s:PTEnable()
endif
endfunction
command! PTToggle call s:PTToggle()
" }}}
" {{{ nvim-tree.lua
nnoremap <silent><A-0> :NvimTreeToggle<CR>
hi NvimTreeIndentMarker guifg=#3c3836
hi NvimTreeFolderIcon guifg=#7c6f64
hi NvimTreeGitDirty guifg=#689d6a
lua << EOF
require 'nvim-tree'.setup{
git = { ignore = true },
disable_netrw = true,
update_focused_file = { enable = true },
update_cwd = true,
filters = { custom = { '.git', 'node_modules', '.cache', '__pycache__', '.clangd' } },
}
EOF
" }}}
" {{{ telescope.nvim and the related plugins
lua << EOF
local telescope = require("telescope")
local trouble = require("trouble.providers.telescope")
telescope.setup {
defaults = {
preview = {
treesitter = false
},
mappings = {
i = { ["<c-t>"] = trouble.open_with_trouble },
n = { ["<c-t>"] = trouble.open_with_trouble },
},
},
}
EOF
nnoremap <A-p> <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fs <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>b <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>fo <cmd>lua require('telescope.builtin').oldfiles()<cr>
nnoremap <A-u> <cmd>lua require('telescope.builtin').spell_suggest()<cr>
nnoremap gr <cmd>lua require('telescope.builtin').lsp_references()<cr>
nnoremap gs <cmd>lua require('telescope.builtin').lsp_document_symbols()<cr>
nnoremap gd <cmd>lua require('telescope.builtin').lsp_definitions()<cr>
nnoremap gi <cmd>lua require('telescope.builtin').lsp_implementations()<cr>
nnoremap <localleader>a <cmd>lua vim.lsp.buf.code_action()<cr>
nnoremap <localleader>vc <cmd>lua require('telescope.builtin').git_commits()<cr>
nnoremap <localleader>vC <cmd>lua require('telescope.builtin').git_bcommits()<cr>
nnoremap <localleader>vB <cmd>lua require('telescope.builtin').git_branches()<cr>
nnoremap <localleader>vS <cmd>lua require('telescope.builtin').git_stash()<cr>