-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path.vimrc
1407 lines (1241 loc) · 38.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
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
" These may be necessary to work inside the ipython-slime mode
"
" set runtimepath+=/home/ttsiod/.vim
" runtime autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
"""""""""
" VimPlug
"""""""""
call plug#begin('~/.vim/plugged')
" Plug 'neoclide/coc.nvim', {'for':['zig','cmake','rust',
" \'java','json', 'haskell', 'ts','sh', 'cs',
" \'yaml', 'c', 'cpp', 'd', 'go',
" \'python', 'dart', 'javascript', 'vim'], 'branch': 'release'}
Plug 'neoclide/coc.nvim', { 'branch': 'release'}
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf', { 'do': './install --all' } | Plug 'junegunn/fzf.vim'
Plug 'junegunn/fzf.vim'
call plug#end()
"""""""""""""""""""""""""""""
" Generic, all buffer stuff
"""""""""""""""""""""""""""""
se nobackup
se directory=~/.vim/swp,.
se shiftwidth=4
se sts=4
se modelines=2
se modeline
se nocp
se mouse=a
if has("autocmd")
filetype on
filetype indent on
filetype plugin on
endif
" se autoindent
se undofile
se undodir=~/.vimundo
"noremap <ESC>OP <F1>
" ESC is too far away - and Steve Losh is right, this is better than jj
inoremap jk <esc>
" auto-closes preview window after you select what to auto-complete with
"autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
"autocmd InsertLeave * if pumvisible() == 0|pclose|endif
"
" Stop moving the cursor to the beginning of the line (in many move commands)
"
se nostartofline
"
" Very efficient moves amongst local lines, shows relative jump distances
"
se relativenumber
if v:version >= 704
"
" ...but also show the absolute number of the current line.
" Best of both worlds! (only for vim>=7.4)
"
set number
endif
"
" Better TAB completion for files (like the shell)
"
if has("wildmenu")
set wildmenu
set wildmode=longest:list,full
" Ignore stuff (for TAB autocompletion)
set wildignore+=*.a,*.o
set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png
set wildignore+=.DS_Store,.git,.hg,.svn
set wildignore+=*~,*.swp,*.tmp
endif
""""""""""""""""""""
" NERDTree section "
""""""""""""""""""""
" maps NERDTree to F10
" (normal, visual and operator-pending modes)
noremap <silent> <F10> :NERDTreeToggle<CR>
" (also in insert and command-line modes)
noremap! <silent> <F10> <ESC>:NERDTreeToggle<CR>
" tell NERDTree to use ASCII chars
" and to ignore some files
let g:NERDTreeDirArrows=0
let g:NERDTreeIgnore=['\.pyc$', '\.o$']
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" My attempt at easy navigation/creation of windows: "
" Ctrl-Cursor keys to navigate open windows "
" Ctrl-F12 to close current window "
" Also... "
" F4 to navigate to next error in the error window "
" (e.g. after :make) "
" F3 to navigate to next place in location list "
" (e.g. SyntasticLint - but first invoke :Errors) "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
" if (t:curwin == winnr())
" " we havent moved
" " Create window in that direction,
" if (match(a:key,'[jk]')) "were we going up/down
" wincmd v
" else
" wincmd s
" endif
" exec "wincmd ".a:key
" endif
endfunction
function! WinClose()
if &filetype == "man"
bd!
else
bd
endif
endfunction
" Unfortunately, normal key mappings don't work under Win/PuTTY,
" so I have to create these messy Ctrl-v based mappings...
if !has("gui_running")
" XTerm
noremap <silent> <Esc>[1;5B :call WinMove('j')<CR>
noremap <silent> <Esc>[1;5A :call WinMove('k')<CR>
noremap <silent> <Esc>[1;5D :call WinMove('h')<CR>
noremap <silent> <Esc>[1;5C :call WinMove('l')<CR>
noremap <silent> <Esc>[24~ :call WinClose()<CR>
noremap! <silent> <Esc>[1;5B <ESC>:call WinMove('j')<CR>
noremap! <silent> <Esc>[1;5A <ESC>:call WinMove('k')<CR>
noremap! <silent> <Esc>[1;5D <ESC>:call WinMove('h')<CR>
noremap! <silent> <Esc>[1;5C <ESC>:call WinMove('l')<CR>
noremap! <silent> <Esc>[24~ <ESC>:call WinClose()<CR>
noremap <silent> <Esc>OS :cn<CR>
noremap! <silent> <Esc>OS <ESC>:cn<CR>
noremap <silent> <Esc>OR :lnext<CR>
noremap! <silent> <Esc>OR <ESC>:lnext<CR>
noremap <silent> <Esc>[1;5S :bd<CR>
noremap! <silent> <Esc>[1;5S <ESC>:bd<CR>
" Putty-ing from Windows
"
if has("unix")
let myosuname = system("uname")
if myosuname =~ "OpenBSD"
" Putty-ing from Windows into OpenBSD
noremap <silent> <Esc>[B :call WinMove('j')<CR>
noremap <silent> <Esc>[A :call WinMove('k')<CR>
noremap <silent> <Esc>[D :call WinMove('h')<CR>
noremap <silent> <Esc>[C :call WinMove('l')<CR>
noremap <silent> <Esc>[24~ :call WinClose()<CR>
noremap! <silent> <Esc>[B <ESC>:call WinMove('j')<CR>
noremap! <silent> <Esc>[A <ESC>:call WinMove('k')<CR>
noremap! <silent> <Esc>[D <ESC>:call WinMove('h')<CR>
noremap! <silent> <Esc>[C <ESC>:call WinMove('l')<CR>
noremap! <silent> <Esc>[24~ <ESC>:call WinClose()<CR>
noremap <silent> <Esc>[14~ :cn<CR>
noremap! <silent> <Esc>[14~ <ESC>:cn<CR>
elseif &term == "xterm-color"
" Putty-ing from Windows into Linux
noremap <silent> <Esc>OB :call WinMove('j')<CR>
noremap <silent> <Esc>OA :call WinMove('k')<CR>
noremap <silent> <Esc>OD :call WinMove('h')<CR>
noremap <silent> <Esc>OC :call WinMove('l')<CR>
noremap <silent> <Esc>[24~ :call WinClose()<CR>
noremap! <silent> <Esc>OB <ESC>:call WinMove('j')<CR>
noremap! <silent> <Esc>OA <ESC>:call WinMove('k')<CR>
noremap! <silent> <Esc>OD <ESC>:call WinMove('h')<CR>
noremap! <silent> <Esc>OC <ESC>:call WinMove('l')<CR>
noremap! <silent> <Esc>[24~ <ESC>:call WinClose()<CR>
noremap <silent> <Esc>[14~ :cn<CR>
noremap! <silent> <Esc>[14~ <ESC>:cn<CR>
endif
endif
else
" GVim
noremap <silent> <C-Down> :call WinMove('j')<CR>
noremap <silent> <C-Up> :call WinMove('k')<CR>
noremap <silent> <C-Left> :call WinMove('h')<CR>
noremap <silent> <C-Right> :call WinMove('l')<CR>
noremap <silent> <F12> :call WinClose()<CR>
noremap! <silent> <C-Down> <ESC>:call WinMove('j')<CR>
noremap! <silent> <C-Up> <ESC>:call WinMove('k')<CR>
noremap! <silent> <C-Left> <ESC>:call WinMove('h')<CR>
noremap! <silent> <C-Right> <ESC>:call WinMove('l')<CR>
noremap! <silent> <F12> <ESC>:call WinClose()<CR>
noremap <silent> <F4> :cn<CR>
noremap! <silent> <F4> <ESC>:cn<CR>
noremap <silent> <F3> :ln<CR>
noremap! <silent> <F3> <ESC>:ln<CR>
noremap <silent> <C-F4> :bd<CR>
noremap! <silent> <C-F4> <ESC>:bd<CR>
endif
"
" In normal mode, + and - vertically enlarge/shrink a split
" Their shifted versions (= and _) do it horizontally.
"
" Note: this means that the usual gg=G will no longer indent;
" use visual selection: ggVG= (or just map it to your own macro)
"
nnoremap <silent> = :call WinMove('+')<CR>
nnoremap <silent> - :call WinMove('-')<CR>
nnoremap <silent> + :call WinMove('>')<CR>
nnoremap <silent> _ :call WinMove('<')<CR>
"
"when the vim window is resized resize the vsplit panes as well
"
au VimResized * exe "normal! \<c-w>="
"
" incremental search that highlights results
"
se incsearch
se hlsearch
" Ctrl-L clears the highlight from the last search
noremap <C-l> :nohlsearch<CR><C-l>
noremap! <C-l> <ESC>:nohlsearch<CR><C-l>
"
" Use FZF history
"
noremap <leader>h :History<CR>
"
" Fix insert-mode cursor keys in FreeBSD
"
if has("unix")
let myosuname = system("uname")
if myosuname =~ "FreeBSD"
set term=cons25
endif
endif
"
" Reselect visual block after indenting
"
vnoremap < <gv
vnoremap > >gv
"
" Keep search pattern at the center of the screen
"
"nnoremap <silent> n nzz
"nnoremap <silent> N Nzz
"nnoremap <silent> * *zz
"nnoremap <silent> # #zz
" Horizontally center cursor position.
" Does not move the cursor itself (except for 'sidescrolloff' at the window
" border).
nnoremap <leader>z :<C-u>normal! zszH<CR>
"
" Make Y behave like other capitals
"
"noremap Y y$
"
" Force Saving Files that Require Root Permission
"
cnoremap w!! %!sudo tee > /dev/null %
"
" TAB and Shift-TAB in normal mode cycle buffers
"
noremap <Tab> :bn<CR>
noremap <S-Tab> :bp<CR>
"
" Syntax-coloring of files
"
syntax on
" colorscheme default
" colorscheme elflord
" colorscheme desert
" colorscheme catppuccin-mocha
colorscheme evening
" colorscheme delek " from home
" colorscheme catppuccin-latte
" se nowrap " from home
"
" Disable cursors (force myself to learn VI moves)
" Months later: It worked - I now only use the home row.
" Leaving it here for any one else needing it.
"
"map <down> <nop>
"map <left> <nop>
"map <right> <nop>
"map <up> <nop>
"
"imap <down> <nop>
"imap <left> <nop>
"imap <right> <nop>
"imap <up> <nop>
"
" highlight current line
"
set cursorline
"
" always show the status line
"
set laststatus=2
set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v]
" | | | | | | | | | | |
" | | | | | | | | | | + current
" | | | | | | | | | | column
" | | | | | | | | | +-- current line
" | | | | | | | | +-- current % into file
" | | | | | | | +-- current syntax in
" | | | | | | | square brackets
" | | | | | | +-- current fileformat
" | | | | | +-- number of lines
" | | | | +-- preview flag in square brackets
" | | | +-- help flag in square brackets
" | | +-- readonly flag in square brackets
" | +-- rodified flag in square brackets
" +-- full path to file in the buffer
"
" We must be able to show the 80 column limit with F9...
" While we're at it, we'll also show TABs and trailing WS.
" Hitting F9 again will toggle back to normal.
"
" Default: no column
set colorcolumn=
function! TabsAndColumn80AndNumbers ()
set listchars=tab:>-,trail:-
set list!
if exists('+colorcolumn')
" Show column 80
if &colorcolumn == ""
set colorcolumn=80
set norelativenumber!
set number!
else
set colorcolumn=
endif
endif
endfunction
noremap <silent> <Esc>[20~ :call TabsAndColumn80AndNumbers()<CR>
noremap! <silent> <Esc>[20~ <ESC>:call TabsAndColumn80AndNumbers()<CR>
noremap <silent> <F9> :call TabsAndColumn80AndNumbers()<CR>
noremap! <silent> <F9> <ESC> :call TabsAndColumn80AndNumbers()<CR>
"
" Smart backspace
"
set backspace=start,indent,eol
"
" Avoid TABs like the plague
"
set expandtab
" SVN/GIT vimdiff hack:
"
" For SVN:
"
" in ~/.subversion/config:
"
" diff-cmd = /usr/local/bin/svndiff
"
" and this helper cmd is simply...
"
" $ cat /usr/local/bin/svndiff
" #!/bin/bash
" vimdiff "$6" "$7"
" exit 0
"
" (s/vimdiff/meld/ or whatever else you fancy...)
"
" For GIT:
"
" in ~/.gitconfig:
"
" ....
" [diff]
" external = git_diff_wrapper
"
" [pager]
" diff =
"
" and this wrapper is simply...
"
" $ cat /usr/local/bin/git_diff_wrapper
" #!/bin/sh
" vimdiff "$2" "$5"
" exit 0
" (s/vimdiff/meld/ or whatever else you fancy...)
"
" Inside vimdiff, enable wrap (visible diffs past 80 columns)
" au FilterWritePre * if &diff | set wrap | endif
" Set vimdiff to ignore whitespace
set diffopt+=iwhite
set diffexpr=
"
" Much improved auto completion menus
"
set completeopt=menuone,longest,preview
"
" Use C-space for omni completion in insert mode.
"
" inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
" \ "\<lt>C-n>" :
" \ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
" \ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
" \ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
" imap <C-@> <C-Space>
" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>
"
" Stop warning me about leaving a modified buffer
"
set hidden
"
" Show keystrokes as I type (command mode)
"
set showcmd
"
" Now that I use vim-paren-crosshairs, I need 256 colors in my console VIM
"
set t_Co=256
"
" After 'f' in normal mode, I always mistype 'search next' - use space for ';'
"
noremap <space> ;
"
" Manpage for word under cursor via 'K' in command mode
"
runtime ftplugin/man.vim
noremap <buffer> <silent> K :exe "Man" expand('<cword>') <CR>
"
" Now that I use the CtrlP plugin, a very useful shortcut is to open
" an XTerm in the folder of the currently opened file:
"
" noremap <silent> <F5> :!gnome-terminal -e "$SHELL --login -c 'cd %:p:h ; $SHELL'" &<CR><CR>
" noremap <silent> <Esc>OQ :!gnome-terminal -e "$SHELL --login -c 'cd %:p:h ; $SHELL'" &<CR><CR>
noremap <silent> <F5> :!xterm -e "cd %:p:h ; bash" &<CR><CR>
"noremap <silent> <Esc>OQ :!xterm -e "cd %:p:h ; bash" &<CR><CR>
let g:ctrlp_working_path_mode = 0
let g:ctrlp_max_files=0
let g:ctrlp_max_depth=100
let g:ctrlp_custom_ignore='.git$|obj/|tmp$|preproce.*$'
" Unfortunately, reusing the cache caused more harm than good
" let g:ctrlp_clear_cache_on_exit = 1
"
" Powerline settings
"
let g:Powerline_stl_path_style = 'short'
"
" For GVIM only
"
if has("gui_running")
" Horizontal scrollbar
set guioptions+=b
set nowrap
set guifont=Lucida\ Console\ Semi-Condensed\ 11
colorscheme evening
endif
" Toggle wrap/nowrap
nnoremap <silent> <leader>w :windo set wrap!<cr>
"
" Sacrilege: Make Ctrl-c act as 'Clipboard-copy' in visual select mode
"
vnoremap <C-c> "+y
"
" Default to very magic (I prefer normal Perl-y regexps)
"
nnoremap / /\v
vnoremap / /\v
"
" cd to the currently opened file's folder
"
command! Cdd cd %:p:h
"
" Greek-locale normal maps
"
noremap α a
noremap β b
noremap ψ c
noremap δ d
noremap ε e
noremap φ f
noremap γ g
noremap η h
noremap ι i
noremap ξ j
noremap κ k
noremap λ l
noremap μ m
noremap ν n
noremap ο o
noremap π p
noremap ρ r
noremap σ s
noremap τ t
noremap θ u
noremap ω v
noremap ς w
noremap χ x
noremap υ y
noremap ζ z
noremap Α A
noremap Β B
noremap Ψ C
noremap Δ D
noremap Ε E
noremap Φ F
noremap Γ G
noremap Η H
noremap Ι I
noremap Ξ J
noremap Κ K
noremap Λ L
noremap Μ M
noremap Ν N
noremap Ο O
noremap Π P
noremap Ρ R
noremap Σ S
noremap Τ T
noremap Θ U
noremap Ω V
noremap Σ W
noremap Χ X
noremap Υ Y
noremap Ζ Z
"
" Use EasyMotion to go anywhere in the screen in normal mode, with just '!'
"
nmap ! H\\w
"
" Somehow, in my latest update, a big foldcolumn appeared. Nip it in the bud!
"
se foldcolumn=0
"
" Reroute the :Ack to use the silver searcher - warp speed!
"
let g:ackprg = 'ag --nogroup --nocolor --column'
"
" VIMDIFF is far more useful when ignoring whitespace
"
set diffopt+=iwhite
set diffexpr=DiffW()
function DiffW()
let opt = ""
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-w " " swapped vim's -b with -w
endif
silent execute "!diff -a --binary " . opt .
\ v:fname_in . " " . v:fname_new . " > " . v:fname_out
endfunction
"
" Gitgutter use popup windows
"
let g:gitgutter_preview_win_floating = 1
"
" Gitgutter easier diff/stage/unstage
"
nnoremap <silent> <leader>d :GitGutterPreviewHunk<CR>
nnoremap <silent> <leader>s :GitGutterStageHunk<CR>
nnoremap <silent> <leader>u :GitGutterUndoHunk<CR>
nnoremap <silent> <F1> :GitGutterNextHunk<CR>
"
" Auto comment/uncomment
"
nnoremap <silent> <leader>c :Commentary<CR>
vnoremap <silent> <leader>c :Commentary<CR>
"""""""""""""""""""""""""""""""""""""""""""""
"
" Language-specific section
"
"""""""""""""""""""""""""""""""""""""""""""""
" OBSOLETE - Disabled.
"
" First, use session management
" (From http://pm.veritablesoftware.com/slides/vim_for_perl_development/session_code.vimrc.html)
"
"
" Autoload and autosave sessions.
autocmd VimEnter * call AutoLoadSession()
autocmd VimLeave * call AutoSaveSession()
function! AutoLoadSession()
if argc() == 0
perl << EOD
use Digest::MD5 qw(md5_hex);
use Cwd;
my $session_md5_hash = md5_hex(cwd());
my $session_path = "$ENV{HOME}/.vim/sessions/$session_md5_hash.session";
if (-e $session_path) {
VIM::DoCommand("silent source $session_path");
}
EOD
endif
endfunction
function! AutoSaveSession()
if argc() == 0
perl << EOD
use Digest::MD5 qw(md5_hex);
use Cwd;
my $session_md5_hash = md5_hex(cwd());
my $session_path = "$ENV{HOME}/.vim/sessions/$session_md5_hash.session";
VIM::DoCommand("silent mksession! $session_path");
EOD
endif
endfunction
"
" Tell Syntastic which files should be passive
" (and wait for user to press F7/F6 for validation)
"
let g:syntastic_mode_map = {
\ 'mode': 'active',
\ 'active_filetypes': [],
\ 'passive_filetypes': ['python', 'cpp', 'c', 'typescript', 'java'] }
"
" For C and C++, use libclang, Luke.
"
let g:clang_use_library = 1
let g:clang_library_path = "/lib/x86_64-linux-gnu"
"
" Auto-format on save is sometimes wanted and sometimes not.
"
"
let g:clang_format_on_save = 1
function ToggleFormatOnSave()
if g:clang_format_on_save == 1
let g:clang_format_on_save = 0
echo "Auto-format on save disabled"
else
let g:clang_format_on_save = 1
echo "Auto-format on save ENABLED"
endif
endfunction
function AutoSaveMaybe()
if g:clang_format_on_save == 1
echo "Formating ".line('$')." lines..."
silent! execute ':ClangFormat'
endif
endfunction
" (for CUDA .cu, too)
au BufNewFile,BufRead *.c,*.h call SetupCenviron()
au BufNewFile,BufRead *.cc,*.cpp,*.hh,*.cu call SetupCPPenviron()
au BufWritePre *.cpp call AutoSaveMaybe()
au BufWritePre *.cc call AutoSaveMaybe()
au BufWritePre *.c call AutoSaveMaybe()
au BufWritePre *.cu call AutoSaveMaybe()
au BufWritePre *.h call AutoSaveMaybe()
au BufWritePre *.hpp call AutoSaveMaybe()
fun! ShowFuncName()
echohl ModeMsg
echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bWn'))
echohl None
endfun
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300
function! SetupCandCPPenviron()
"
" Search path for 'gf' command (e.g. open #include-d files)
"
"set path+=/usr/include/c++/**
"
" For the ':A' (plugin) that swaps between header and impl file (C/C++)
let g:alternateExtensions_cc = "inc,h,H,HPP,hpp"
let g:alternateExtensions_CC = "inc,h,H,HPP,hpp"
let g:alternateExtensions_cpp = "inc,h,H,HPP,hpp"
let g:alternateExtensions_CPP = "inc,h,H,HPP,hpp"
"
" Tags
"
" If I ever need to generate tags on the fly, I uncomment this:
" noremap <C-F11> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
" set tags+=/usr/include/tags
"
" Toggle TagList window with F8
"
noremap <buffer> <silent> <F8> :TlistToggle<CR>
noremap! <buffer> <silent> <F8> <ESC>:TlistToggle<CR>
let g:Tlist_Use_Right_Window = 1
"
" Especially for C and C++, use section 3 of the manpages
"
noremap <buffer> <silent> K :exe "Man" 3 expand('<cword>') <CR>
"
" F5 to toggle using clang-format to update on save - or not!
" "
noremap <silent> <F5> :call ToggleFormatOnSave()<CR>
"
" F6 to see the CocDiagnostics output
"
noremap <silent> <F6> :CocDiagnostics<CR>
"
" Remap F7 to make
"
noremap <buffer> <special> <F7> :make<CR>
noremap! <buffer> <special> <F7> <ESC>:make<CR>
"
" Remap F3 to show function name
"
noremap <buffer> <special> <F3> :CocCommand document.toggleInlayHint<CR>
noremap <buffer> <Esc>OR :CocCommand document.toggleInlayHint<CR>
"
" Use the tags, Luke
"
noremap <buffer> <C-]> :tag <C-R>=expand('<cword>')<CR><CR>
"
" Use Coc to rename, Luke (with F2)
"
noremap <buffer> <silent> <F2> :CocCommand document.renameCurrentWord<CR>
"
" Work prefers these settings.
" After using them for quite a while, I guess I like them too :-)
"
se shiftwidth=2
se sts=2
"
" coc.nvim and LSP stuff. Mostly copied from here:
" https://github.com/neoclide/coc.nvim#example-vim-configuration
"
" Show me what you know about the symbol under the cursor
nnoremap <silent> <leader>i :call CocActionAsync('doHover')<cr>
" Refresh the clang diagnostics shown by Coc
nnoremap <silent> <leader>r :CocRestart<cr>
" DEPRECATED Apply clang-tidy fixes to C++ code
" nnoremap <leader>f :execute ':!clang-tidy -p ' . shellescape(getcwd()) . ' --checks=modernize-type-traits --fix % -- -std=c++20 -x c++'<cr>
" Better yet, choose one of the available actions from the LSP.
nnoremap <leader>f <Plug>(coc-codeaction-cursor)
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" 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>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" 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> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
endfunction
function! SetupCenviron()
call SetupCandCPPenviron()
set commentstring=/*%s*/
endfunction
function! SetupCPPenviron()
call SetupCandCPPenviron()
set commentstring=//%s
endfunction
"
" For Python
"
au BufNewFile,BufRead *.py call SetupPythonEnviron()
function! SetupPythonEnviron()
"
" flake8: ignore 'too long lines'
"
let g:flake8_ignore="E501,E225,C103"
"
" Function that sends individual Python classes or Python functions
" to active screen (SLIME emulation)
"
function! SelectClassOrFunction ()
let s:currLine = getline(line('.'))
if s:currLine =~ '^def\|^class'
" If the cursor line is a function/class start line,
" save its number
let s:beginLineNumber = line('.')
elseif s:currLine =~ '^[a-zA-Z]'
" If the cursor line begins with something else,
" we must be on something like a global assignment
let s:beginLineNumber = line('.')
let s:endLineNumber = line('.')
:exe ":" . s:beginLineNumber . "," . s:endLineNumber . "y r"
:call Send_to_Screen(@r)
return
else
" we are inside something, so search backwards
" for function/class beginning, and save its number
let s:beginLineNumber = search('^def\|^class', 'bnW')
if !s:beginLineNumber
let s:beginLineNumber = 1
endif
endif
" Now search for the first line that starts with something
" (function, class, global, etc) and save it
let s:endLineNumber = search('^[a-zA-Z@]', 'nW')
if !s:endLineNumber
let s:endLineNumber = line('$')
else
let s:endLineNumber = s:endLineNumber-1
endif
" Finally pass the range to the screen session running a REPL
:exe ":" . s:beginLineNumber . "," . s:endLineNumber . "y r"
:call Send_to_Screen(@r)
endfunction
noremap <buffer> <silent> <C-c><C-c> :call SelectClassOrFunction()<CR><CR>
"
" Flake8 is always at F7 - but syntastic must use pylint
"
let g:syntastic_python_checker = 'pylint'
"
" Syntastic - Ignore 'too long lines' and 'missing whitespace around op'
"
let g:syntastic_python_checker_args = "--ignore=E501,E225"
let g:syntastic_python_pylint_post_args = "--disable=C0103,C0301,W0212,C0111"
"
" Map SyntasticCheck to F6
"
noremap <buffer> <silent> <F6> :SyntasticCheck<CR>
noremap! <buffer> <silent> <F6> <ESC>:SyntasticCheck<CR>
" Somehow, ts for python files is autoset to 4.
" Only sts should be 4, nothing else.
set ts=8
"
" Jedi auto-completion
"
:setlocal omnifunc=jedi#completions
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" 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>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
endfunction
"
" OCaml
"
"
" Merlin
"
if executable('ocamlmerlin') && has('python')
let s:ocamlmerlin = substitute(system('opam config var share'), '\n$', '', '''') . "/ocamlmerlin"
execute "set rtp+=".s:ocamlmerlin."/vim"
execute "set rtp+=".s:ocamlmerlin."/vimbufsync"
let g:syntastic_ocaml_checkers = ['merlin']
endif
if executable('ocp-indent')
let $OCPPATHVIM = substitute(system('opam config var share'), '\n$', '', '''') . "/vim/syntax/ocp-indent.vim"