-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
1049 lines (979 loc) · 31.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
" vim:set foldmethod=marker foldlevel=0 cursorcolumn cursorline:
" 1. General settings {{{
let os = substitute(system('uname'), "\n", "", "")
let g:coc_disable_startup_warning = 1
" Suppress 'No write since last change'
set hidden
set confirm
" visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
set complete+=k
set complete-=i
" Allow opening C++'s includes using 'gf'
set path+=/usr/include/c++/*
" Fix: http://stackoverflow.com/a/12487439/963881
" argdo set eventignore-=Syntax | tabedit
let mapleader=","
set nocompatible " be iMproved, required
" set noesckeys
set timeoutlen=1000 ttimeoutlen=0
" Replace the current selection with buffer"{{{
"}}}
" Turn off vim recording for good
" map q <Nop>
" Disable Ex mode
map Q <Nop>
set ignorecase " Ignore case when searching
syntax on " Syntax colouring
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
set ruler " Show ruler on the bottom
set virtualedit=onemore
" See: https://unix.stackexchange.com/a/333659/20334
set wrap formatoptions<
" set textwidth=0
" set formatoptions+=w " gggqG - format to break after 80 characters
" set wrapmargin=2
set wrap " don't wrap lines in Insert mode (visual wrapping only)
set autoread " Set to auto read when a file is changed from the outside
" UTF-8 encoding
set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
set title
" For regular expressions turn magic on
set magic
" Alias unnamed register to the + register, which is the X Window clipboard
" Use +p to paste from the X clipboard (or Ctrl-r-+/* in Insert mode)
set clipboard^=unnamed,unnamedplus
" Don't redraw while executing macros (good performance config)
set lazyredraw
set complete+=k
set complete-=i
" Clear terminal before executing the command
" Adding -i significantly slows down Vim's startup
" (it's needed to run aliases though)
" set shell=/bin/bash\ -i
set shell=/bin/bash
" set shell=~/.vim/shell-wrapper.sh
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
" Disable swap file creation"{{{
set noswapfile
"}}}
" Tabs"{{{
set expandtab
set tabstop=4
retab " change all the existing tab characters to match the current tab settings
set shiftwidth=4
"}}}
" Configure the cursor"{{{
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
"}}}
highlight ColorColumn ctermbg=lightgrey guibg=lightgrey
set colorcolumn=80
set dictionary="/usr/dict/words"
set number " Line numbers
" set numberwidth=3
set history=700 " How many lines of history VIM has to remember
set ttyfast
set ttymouse=xterm2
set mouse=a
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "100 : will save up to 100 lines for each register
" :20 : up to 20 lines of command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo
" Enable filetype plugins
filetype plugin on
filetype indent on
" Auto read when a file is changed from the outside
set autoread
" Markdown folding
let g:markdown_folding = 1
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
"Searching"{{{
set incsearch " find as you type search
set hlsearch " highlight search terms
set ignorecase " case insensitive search
set smartcase " case sensitive when uc present
"}}}
set wildmenu " Turn on the WiLd menu
set mouse=a
" Remember to (settings outside the vimrc) "{{{
" 1. Swap Esc and Caps lock
" (http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_XWindows)
""}}}
" }}}
" 2. Key mappings {{{
" Temporary mappings "{{{
au BufEnter,BufNew *.java noremap <F5> :wa \| !javac -verbose % && java %:r : <CR>
" C++ quick compilation
" noremap <F5> :wa \| !clang++ -g -Wall -pthread -std=c++11 % -o test && ./test : <CR>
noremap <F5> :wa \| !clang++ -g -Wall -Wno-missing-braces -pthread -std=c++1z % -o test && ./test : <CR>
" noremap <F5> :wa \| !clang++ -g -Wall -Wno-missing-braces -Wno-unused -std=c++1z % -o test && ./test < ~/test0.in <CR>
" noremap <F6> :wa \| !clang++ -g -Wall -include /usr/include/x86_64-linux-gnu/c++/4.8/bits/stdc++.h -pthread -std=c++11 % -o test && ./test : <CR>
" au BufEnter,BufNew *.c noremap <F5> :wa \| !clang -std=c99 -g % -o test && ./test : <CR>
au BufEnter,BufNew *.c noremap <F5> :wa \| !clang -Wall -g % -lpthread -o test && ./test : <CR>
" au BufEnter,BufNew *.hs noremap <F5> :wa \| !ghci % <CR>
au BufEnter,BufNew *.hs noremap <F5> :wa \| !runhaskell % <CR>
" different F5 keymap for CUDA development
au BufEnter,BufNew *.cu noremap <F5> :wa \| !nvcc -std=c++11 -g % -o test && ./test : <CR>
" Python
au BufEnter,BufNew *.py noremap <F5> :wa \| !python3 % : <CR>
" LaTeX
au BufEnter,BufNew *.tex noremap <F5> :wa \| Lt <CR>
" Shell
au BufEnter,BufNew *.sh noremap <F5> :wa \| !bash % <CR>
" Typescript
au BufEnter,BufNew *.ts noremap <F5> :wa \| !node % <CR>
" JS
au BufEnter,BufNew *.js noremap <F5> :wa \| !node % <CR>
" Go
au BufEnter,BufNew *.go noremap <F5> :wa \| !go run % <CR>
imap <F5> <C-o><F5>
" Open file under cursor in vertical window
nnoremap <F3> :vertical wincmd f<CR>
"}}}
" Control+A is Select All.
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
nnoremap <F3> :vertical wincmd f<CR>
" Ctrl-{X,C,V} under gvim
source $VIMRUNTIME/mswin.vim
behave mswin
silent! unmap <C-F>
" Reformat current file (:w) & save all (:wa; can't reformat all because of
" the way BufWritePre works
noremap <C-S> :w<CR> :wa<CR>
vnoremap <C-S> <C-C>:w<CR>
inoremap <C-S> <C-O>:w<CR>
" leader is ","
nnoremap <leader>q :q<CR>
nnoremap <C-w> :q<CR>
" Fix deleting without yanking
nnoremap <leader>d "_d
vnoremap <leader>d "_d
vnoremap <leader>p "_dP
" Vertical split with leader-w
nnoremap <leader>w <C-w>v<C-w>l
" Control+W closes the current file
" noremap <C-W> :wq<CR>
" Control+Z is Undo, in Normal and Insert mode.
noremap <C-Z> u
inoremap <C-Z> <C-O>u
" Common typos
command WQ wq
command Wq wq
command W w
command Q q
" Window resize via Alt + Shift + arrows
map <A-S-Left> <C-W>>
map <A-S-Right> <C-W><
map <A-S-Up> <C-W>+
map <A-S-Down> <C-W>-
" Tab switching/adding
map <C-Right> <ESC>:tabnext<CR>
map <C-Left> <ESC>:tabprev<CR>
map <C-t> <ESC>:tabnew<CR>
" F2 inserts the date and time at the cursor.
" inoremap <F2> <C-R>=strftime("%c")<CR>
" nmap <F2> a<F2><Esc>
" Window splits {{{
" window
nmap <leader>sw<left> :topleft vnew<CR>
nmap <leader>sw<right> :botright vnew<CR>
nmap <leader>sw<up> :topleft new<CR>
nmap <leader>sw<down> :botright new<CR>
" buffer
nmap <leader>s<left> :leftabove vnew<CR>
nmap <leader>s<right> :rightbelow vnew<CR>
nmap <leader>s<up> :leftabove new<CR>
nmap <leader>s<down> :rightbelow new<CR>
" }}}
" Scroll between open windows
map <F6> <C-W>w
" nnoremap <tab> :wincmd w<cr>
" inoremap <tab> <c-o>:wincmd w<cr>
" Execute current line in bash
nmap <F9> :exec '!'.getline('.')<CR>
" Refactoring variable names "{{{
" Source: http://stackoverflow.com/a/597932/963881
function! Refactor()
call inputsave()
let @z=input("What do you want to rename '" . @z . "' to? ")
call inputrestore()
endfunction
" Locally (local to block) rename a variable
nmap <Leader>rf "zyiw:call Refactor()<cr>mx:silent! norm gd<cr>[{V%:s/<C-R>//<c-r>z/g<cr>`x
"}}}
" Open .vimrc in a tab, on a 'Key mappings' section
command! Vr :tabe ~/.vimrc | execute "normal /Key mappings \<CR><Space>" | nohlsearch
" Remove blank lines
command! RemoveBlankLines :g/^$/d
" Alias for PlugInstall
command! I :PlugInstall
" Replace commands "{{{
command! SpacesToNewline :%s/ /\r/g
command! UnderscoreToNewline :%s/_/\r/g
command! DashesToNewline :%s/-/\r/g
command! ColonToNewline :%s/:/\r/g
command! SemicolonToNewline :%s/;/\r/g
""}}}
" Compile LaTeX and open corresponding LaTeX
" Use LaTeX rather than plain TeX.
let g:tex_flavor = "latex"
" command! Lt :!latexmk -pvc -silent -pdf %; xdg-open %:r.pdf
" command! Lt :!pdflatex % && xpdf %:r.pdf <CR>
command! Lt :!pdflatex % && evince %:r.pdf
" Toggle small/normal tabs
" noremap <F8> :call <SID>ToggleTabs()<CR>
" Double-click to copy word
nnoremap <silent> <2-LeftMouse> byw
" Go-related "{{{
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>r <Plug>(go-run)
au FileType go nmap <Leader>b <Plug>(go-build)
au FileType go nmap <Leader>t <Plug>(go-test)
au FileType go nmap gd <Plug>(go-def-tab)
au Filetype go set makeprg=go\ build\ ./...
function! s:GoVet()
cexpr system("go vet " . shellescape(expand('%')))
copen
endfunction
command! GoVet :call s:GoVet()
function! s:GoLint()
cexpr system("golint " . shellescape(expand('%')))
copen
endfunction
command! GoLint :call s:GoLint()
" vim-go settings
" let g:go_disable_autoinstall = 0
" format with goimports instead of gofmt
let g:go_fmt_command = "goimports"
" disable fmt on save
let g:go_fmt_autosave = 1
let g:go_version_warning = 0
"}}}
" Change behavior of <Space> when there is '"' under the cursor"{{{
" http://stackoverflow.com/a/27669139/963881
" Currently doesn't go along with mapping <Space> to toggle folds
" nnoremap <expr> <space> '"'==matchstr(getline('.'), '\%' . col('.') . 'c.')?"i <ESC>":"<space>"
"}}}
" Arrow keys {{{
" Disable Arrow keys in Escape mode
" map <up> <nop>
"map <down> <nop>
"map <left> <nop>
"map <right> <nop>
" Disable Arrow keys in Insert mode
"imap <up> <nop>
"imap <down> <nop>
"imap <left> <nop>
"imap <right> <nop>
" }}}
" Avoid 'Press ENTER to continue' in Vim when entering man pages (using K) "{{{
nnoremap K K<CR>
vnoremap K K<CR>
"}}}
" make YCM compatible with UltiSnips (using supertab)
" let g:ycm_key_list_select_completion = ['<C-n>', '<Down>', '<C-Space>']
" let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
" let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
" let g:ycm_min_num_of_chars_for_completion = 1
" let g:SuperTabDefaultCompletionType = '<C-n>'
" better key bindings for UltiSnipsExpandTrigger
" let g:UltiSnipsExpandTrigger = "<tab>"
" let g:UltiSnipsJumpForwardTrigger = "<tab>"
" let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
" SnipMate
" let g:snipMate = {}
" let g:snipMate.snippet_version = 1
let g:ycm_global_ycm_extra_conf = "~/dotfiles/ycm_extra_conf.py"
" let g:ycm_server_use_vim_stdout = 1
" let g:ycm_server_log_level = 'debug'
" let g:ycm_path_to_python_interpreter = '/usr/bin/python'
" Space to toggle folding
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
augroup vim
au!
" Help for word under the cursor (.vimrc only)
au FileType vim setlocal keywordprg=:help
augroup END
" Remap code completion to Ctrl+Space {{{
" inoremap <Nul> <C-x><C-o>
" In your case you want:
" inoremap <Nul> <C-n>
" }}}
" Leader key bindings"{{{
" Move back to current position after doing gg=G (code reformat)
map <Leader>f mzgg=G`z<CR>
" Substitute all occurrences of the word under the cursor
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
"Astyle (http://astyle.sourceforge.net/) config {{{
" Format C code (Linux Kernel style)
map <leader>fl :! astyle --style=linux %<CR> :redraw!<CR>
" Format C++ code (Google style)
map <leader>fg :! astyle --style=google %<CR>
" }}}
" }}}
" }}}
" 3. vim-plug config & plugins {{{
call plug#begin()
" The default plugin directory will be as follows:
" " - Vim (Linux/macOS): '~/.vim/plugged'
" " - Vim (Windows): '~/vimfiles/plugged'
" " - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" " You can specify a custom plugin directory by passing it as the argument
" " - e.g. `call plug#begin('~/.vim/plugged')`
" " - Avoid using standard Vim directory names like 'plugin'
" Must-haves "{{{
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'}
" Plug 'neoclide/coc.nvim'
Plug 'rafi/awesome-vim-colorschemes'
Plug 'majutsushi/tagbar'
"}}}
" Plug 'Lokaltog/vim-easymotion'
" Plug 'tpope/vim-vinegar'
" Plug 'wikitopian/hardmode'
"Plug 'Yggdroot/indentLine'
" Plug 'nathanaelkane/vim-indent-guides'
" A Git wrapper so awesome, it should be illegal
" Plug 'tpope/vim-repeat'
" Plug 'tpope/vim-unimpaired' " For jumping to errors shortcuts
" undle 'tpope/vim-fugitive'
" Plug 'vim-scripts/gtags.vim'
" Plug 'thinca/vim-quickrun'
" Plug 'vim-scripts/netrw.vim'
" Plug 'jondkinney/dragvisuals.vim'
" Plug 'nixon/vim-vmath'
Plug 'itspriddle/vim-shellcheck'
" Plug 'taku-o/vim-vis'
" Plug 'rking/ag.vim'
Plug 'darfink/vim-plist'
Plug 'jamessan/vim-gnupg'
" Plug 'Raimondi/delimitMate'
Plug 'digitalrounin/vim-yaml-folds'
" Plug 'terryma/vim-multiple-cursors'
" Plug 'rking/ag.vim'
" Assembly
" Plug 'vim-scripts/asmx86'
" JavaScript (temporary - for Node.js) {{{
Plug 'lukaszb/vim-web-indent'
Plug 'digitaltoad/vim-jade'
Plug 'Chiel92/vim-autoformat'
" }}}
" Color schemes "{{{
Plug 'morhetz/gruvbox'
Plug 'changyuheng/color-scheme-holokai-for-vim'
Plug 'sjl/badwolf'
Plug 'altercation/vim-colors-solarized'
Plug 'vim-scripts/orangeocean256'
" Plug 'Lokaltog/vim-distinguished'
" Plug 'jnurmine/Zenburn'
Plug 'vim-scripts/torte.vim'
" Plug 'vim-scripts/Wombat'
Plug 'tpope/vim-vividchalk'
Plug 'croaker/mustang-vim'
" "}}}
" Language-specific
" C++ {{{
Plug 'rhysd/vim-clang-format'
" Plug 'Mizuchi/STL-Syntax'
" Plug 'rmartinho/vim-cpp11'
" C++ IDE-related {{{
Plug 'vim-scripts/a.vim'
" Plug 'DoxygenToolkit.vim'
" Plug 'godlygeek/tabular'
" Plug 'tpope/vim-sensible'
" Plug 'tpope/vim-unimpaired'
" Plug 'tpope/vim-endwise'
" Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" Plug 'Lokaltog/vim-easymotion'
" Plug 'rstacruz/sparkup'
" }}}
" }}}
" Python {{{
Plug 'tmhedberg/SimpylFold'
" Plug 'nvie/vim-flake8'
" Plug 'klen/python-mode'
" }}}
" Haskell (http://haskelllive.com/environment.html) {{{
" Plug 'lukerandall/haskellmode-vim'
" Plug 'eagletmt/ghcmod-vim'
Plug 'bitc/lushtags'
Plug 'raichoo/haskell-vim'
Plug 'eagletmt/neco-ghc'
" }}}
" Smalltalk {{{
" Plug 'vim-scripts/st.vim'
" }}}
" Prolog {{{
Plug 'adimit/prolog.vim'
" }}}
" Promela {{{
Plug 'vim-scripts/promela.vim'
" }}}
" Go {{{
Plug 'fatih/vim-go'
" }}}
" Plug 'stefandtw/quickfix-reflector.vim'
" Plug 'vim-scripts/linuxsty.vim'
"Plug 'bling/vim-airline'
"Plug 'kana/vim-operator-user' " Recommended by clang-format
" Plug 'vim-scripts/vim-auto-save'
Plug 'kien/ctrlp.vim' " For tag creation
Plug 'tacahiroy/ctrlp-funky'
" Plug 'christoomey/vim-tmux-navigator'
" Plug 'https://bitbucket.org/ns9tks/vim-l9' " Plug throws: repo not found
" Plug 'https://bitbucket.org/ns9tks/vim-fuzzyfinder' " Plug throws: repo not found
" Latex
" Plug 'gerw/vim-latex-suite'
" Plug 'lervag/vim-latex'
" Plug 'jamis/fuzzy_file_finder'
" Plug 'jamis/fuzzyfinder_textmate'
" Git commits "{{{
" Allow longer commit message titles (default: 72)
autocmd Filetype gitcommit setlocal spell textwidth=256
" "}}}
" "}
" Snippets {{{
Plug 'ervandew/supertab'
" Plug 'SirVer/ultisnips'
" SnipMate
Plug 'MarcWeber/vim-addon-mw-utils'
" Plug 'tomtom/tlib_vim'
" Plug 'garbas/vim-snipmate'
Plug 'honza/vim-snippets'
" }}}
" All of your Plugins must be added before the following line
call plug#end() " required
filetype plugin indent on " required
" }}}
" 4. CoC plugin config {{{
" install CoC plugins:
" :CocInstall coc-tsserver coc-eslint coc-json coc-prettier coc-css coc-html coc-snippets
"CoC Settings
" 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()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" 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>"
"Ultisnips Settings
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
"coc-snippets Settings
"inoremap <silent><expr> <TAB>
" \ coc#pum#visible() ? coc#_select_confirm() :
" \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
" \ CheckBackspace() ? "\<TAB>" :
" \ coc#refresh()
"
"function! CheckBackspace() abort
" let col = col('.') - 1
" return !col || getline('.')[col - 1] =~# '\s'
"endfunction
"
"let g:coc_snippet_next = '<tab>'
" }}}
" 5. UI {{{
" GVim "{{{
if os == "Darwin"
set guifont=Monaco:h18
endif
set guioptions=a
""}}}
" Search"{{{
hi Search ctermfg=Yellow ctermbg=NONE cterm=bold,underline
"}}}
" Status line {{{
if has('statusline')
set laststatus=2
set statusline+=col:\ %c,
" Broken down into easily includeable segments
" set statusline=%<%f\\ " Filename
" set statusline+=%w%h%m%r " Options
" set statusline+=%{fugitive\#statusline()} " Git Hotness
" set statusline+=\\ [%{&ff}/%Y] " filetype
" set statusline+=\\ [%{getcwd()}] " current dir
" set statusline+=\\ [A=\\%03.3b/H=\\%02.2B] " ASCII/hex value of char
" set statusline+=%=%-14.(%l,%c%V%)\\ %p%% " Right aligned file nav info
endif
" }}}
" Solarized theme configuration {{{
set t_Co=256
let g:solarized_termcolors=256
" let g:solarized_termtrans = 1
let g:solarized_degrade = 1
" let g:solarized_bold = 1
" let g:solarized_underline = 1 | 0
" let g:solarized_italic = 1 | 0
let g:solarized_contrast = "high"
let g:solarized_visibility= "high"
try
" colorscheme solarized
" colorscheme vividchalk
" colorscheme mustang
" colorscheme badwolf
colorscheme gruvbox
" colorscheme desert
" colorscheme orangeocean256
" colorscheme distinguished
set background=dark
" set background=dark
" execute "set background=" . $BACKGROUND
catch /^Vim\%((\a\+)\)\=:E185/
" Don't load a color scheme.
endtry
" g:solarized_termcolors=16
"}}}
" Cursorline {{{
" set cursorline
" hi CursorLine ctermbg=236
" hi CursorLine term=bold cterm=bold ctermbg=LightCyan guibg=LightCyan
"}}}
" Vim indent guides setup to work with solarized theme"{{{
" let g:indent_guides_enable_on_vim_startup=1
"set ts=4 sw=4 et
"let g:indent_guides_start_level=2
"let g:indent_guides_start_size=1
au VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=black
let g:indent_guides_auto_colors = 0
au VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=darkgrey
" Vim Indent Guides ""{{{
"let g:indent_guides_auto_colors = 1
"augroup indent_guides
"au!
"au BufRead,BufNewFile * IndentGuidesEnable
"augroup END
au VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=black
" au VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=darkgrey
"}}}
"}}}
" Highlight text that goes over 80 characters"{{{
" http://stackoverflow.com/a/235970/963881
" highlight OverLength ctermbg=red ctermfg=white guibg=#592929
" match OverLength /\%81v.\+/"}}}
" CtrlP"{{{
hi CtrlPMatch ctermbg=235 ctermfg=250 guibg=#262626 guifg=#bcbcbc cterm=NONE gui=NONE
"}}}
" Popup menu"{{{
highlight Pmenu ctermfg=3 ctermbg=0 guifg=#ffffff guibg=#0000ff
" make menu selections visible
highlight PmenuSel ctermfg=black ctermbg=gray
"}}}
" Fold colors"{{{
" hi Folded term=standout ctermfg=White ctermbg=233 guifg=241 guibg=233
" hi Folded term=NONE cterm=NONE gui=NONE ctermbg=None
hi Folded term=NONE cterm=bold gui=NONE ctermbg=NONE ctermfg=red
" hi LineNr ctermfg=white ctermbg=none
" set foldtext=""
" Get rid of the dashes
set fillchars="fold: "
hi FoldColumn guibg=darkgrey guifg=white
""}}}
" Function and identifiers colors"{{{
hi Function guifg=red
hi Identifier guifg=red
""}}}
"}}}
" 6. Tags {{{
" Tag dirs "{{{
" This will look in the current directory for "tags", and work up the tree towards
" root until one is found. IOW, you can be anywhere in your source tree instead of
" just the root of it.
set tags=./tags;/
" Going up to root is excessive. I suggest only going up to home instead:
" tags+=tags;$HOME
"}}}
" build tags of your own project with Ctrl-F12"{{{
map <C-F12> :!ctags -R --sort=yes --langmap=C++:+.cu --c++-kinds=+pl --fields=+iaS --extra=+q .<CR>
"}}}
" OCaml support {{{
" au BufRead,BufNewFile *.ml,*.mli compiler ocaml
set sb
" map <F5> :split /tmp/ocaml \| %d \|setlocal ft=omlet \| setlocal autowrite \| r!ocaml < # <CR>
" map <F6> :dr /tmp/ocaml \| %d \|setlocal ft=omlet \|setlocal autowrite \| r!ocaml < # <CR>
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"
let no_ocaml_comments = 1
"}}}
" }}}
" 7. Autocommands {{{
" Binary files "{{{
augroup Binary
au!
au BufReadPre *.bin,*.evm let &bin=1
au BufReadPost *.bin,*.evm if &bin | %!xxd
au BufReadPost *.bin,*.evm set ft=xxd | endif
au BufWritePre *.bin,*.evm if &bin | %!xxd -r
au BufWritePre *.bin,*.evm endif
au BufWritePost *.bin,*.evm if &bin | %!xxd
au BufWritePost *.bin,*.evm set nomod | endif
augroup END
""}}}
" Haskell "{{{
autocmd BufEnter *.hs set formatprg=pointfree
" au FileType haskell nnoremap <buffer> <F1> :HdevtoolsType<CR>
" au FileType haskell nnoremap <buffer> <silent> <F2> :HdevtoolsClear<CR>
" au FileType haskell nnoremap <buffer> <silent> <F3> :HdevtoolsInfo<CR>
" autocmd BufEnter *.hs set formatprg=pointfree
"}}}
" Tab by default "{{{
au VimEnter * set tabpagemax=9999|sil tab ball|set tabpagemax&vim
""}}}
" Specific files"{{{
" au BufRead ~/Documents/Q.txt normal Goi
au BufRead ~/Documents/Q.txt execute "normal Go"|startinsert!
au BufRead ~/.remember execute "normal Go"|startinsert!
"}}}
" Haskell"{{{
" au BufWritePost *.hs GhcModCheckAndLintAsync
"}}}
" .md files as Markdown"{{{
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
"}}}
" C {{{
au FileType c set makeprg=gcc\ %\ &&\ ./a.out
"}}}
" Turn on C++ autocompletion"{{{
" au BufNewFile,BufRead,BufEnter *.cpp,*.hpp set omnifunc=omni#cpp#complete#Main
"}}}
" Open all files in tabs after entering Vim (though power users prefer buffers)"{{{
au VimEnter * tab all
"}}}
" }}}
" 8. Folds {{{
" set foldmethod=indent " Fold based on indent
" Causes problems with opening some JSON files
" set foldmethod=syntax " Fold based on syntax
set foldnestmax=3 " Deepest fold is 3 levels
set foldlevelstart=5
let javaScript_fold=1 " JavaScript
let sh_fold_enabled=1 " sh
let xml_syntax_folding=1 " XML
"}}}
" 9. Helper functions {{{
" Get info for specific key mapping (show grep output in a dialog) {{{
function! MappingInfo(mapping)
execute "silent !grep -iB 1 " . a:mapping . " ~/.vimrc > minfo.tmp && dialog --textbox minfo.tmp 22 70 && rm minfo.tmp && clear"
redraw!
endfunction
command! -nargs=1 Minfo call MappingInfo(<f-args>)
" "}}}
" Add ranger as a file chooser in vim {{{
" If you add this code to the .vimrc, ranger can be started using the command
" ":RagerChooser" or the keybinding "<leader>r". Once you select one or more
" files, press enter and ranger will quit again and vim will open the selected
" files.
function! RangeChooser()
let temp = tempname()
" The option "--choosefiles" was added in ranger 1.5.1. Use the next line
" with ranger 1.4.2 through 1.5.0 instead.
"exec 'silent !ranger --choosefile=' . shellescape(temp)
exec 'silent !ranger --choosefiles=' . shellescape(temp)
if !filereadable(temp)
redraw!
" Nothing to read.
return
endif
let names = readfile(temp)
if empty(names)
redraw!
" Nothing to open.
return
endif
" Edit the first item.
exec 'edit ' . fnameescape(names[0])
" Add any remaning items to the arg list/buffer list.
for name in names[1:]
exec 'argadd ' . fnameescape(name)
endfor
redraw!
endfunction
command! -bar RangerChooser call RangeChooser()
"}}}
" Toogle line number display {{{
" nmap <silent> <F10> :exec &nu==&rnu ? "se nu" : "se rnu"<CR>
" nnoremap <F10> :set nonumber!<CR>
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber
" set number
else
set relativenumber
endif
endfunc
au FocusLost * :set number
au FocusGained * :set relativenumber
au InsertEnter * :set number
au InsertLeave * :set relativenumber
" Toogle line number display
nnoremap <F10> :call NumberToggle()<cr>
"}}}
" Restore cursor position, window pos., and last search after running a cmd {{{
function! Preserve(command)
" Save the last search.
let search = @/
" Save the current cursor position.
let cursor_position = getpos('.')
" Save the current window position.
normal! H
let window_position = getpos('.')
call setpos('.', cursor_position)
" Execute the command.
execute a:command
" Restore the last search.
let @/ = search
" Restore the previous window position.
call setpos('.', window_position)
normal! zt
" Restore the previous cursor position.
call setpos('.', cursor_position)
endfunction
"}}}
" Re-indent the whole buffer {{{
function! Indent()
call Preserve('normal gg=G')
endfunction
" Indent on save hook
" au BufWritePre <buffer> call Indent()
" ClangFormat on save hook
" autocmd BufWritePre *.h :ClangFormat
" autocmd BufWritePre *.c* :ClangFormat
"}}}
" Modernize C++ code {{{
function! ClangModernize()
:!clang-modernize -style=Google -format -loop-convert -pass-by-value -replace-auto_ptr -use-nullptr -use-auto -add-override -override-macros %
endfunction
command ClangModernize :call ClangModernize()
" }}}
" Toggles tab size between the default width and 1 character width {{{
"b: buffer-local variables
"&l: buffer-local options
"see :help internal-variables
function! s:ToggleTabs ()
if !exists("b:tab_toggler_large")
let b:tab_toggler_large = 1
endif
if b:tab_toggler_large == 0
let b:tab_toggler_large = 1
let &l:ts = b:tab_toggler_ts
let &l:sw = b:tab_toggler_sw
let &l:sts = b:tab_toggler_sts
else
"save the previous tab settings
let b:tab_toggler_large = 0
let b:tab_toggler_ts = &ts
let b:tab_toggler_sw = &sw
let b:tab_toggler_sts = &sts
let &l:ts = 1
let &l:sw = 1
let &l:sts = 1
endif
endfunction
"}}}
" Use TAB to complete when typing words, else inserts TABs as usual {{{
"Uses dictionary and source files to find matching words to complete.
"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
" function! Tab_Or_Complete()
" if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
" return "\<C-N>"
" else
" return "\<Tab>"
" endif
" endfunction
"inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
"}}}
" Automatic insertion of C/C++ header gates/guards {{{
" Creates guards when header file is created
function! s:insert_gates()
let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
execute "normal! i#ifndef " . gatename
execute "normal! o#define " . gatename . " "
execute "normal! Go#endif /* " . gatename . " */"
normal! kk
endfunction
au BufNewFile *.{h,hpp} call <SID>insert_gates()
"}}}
" Jumping through error list {{{
function! <SID>LocationPrevious()
try
lprev
catch /^Vim\%((\a\+)\)\=:E553/
llast
endtry
endfunction
function! <SID>LocationNext()
try
lnext
catch /^Vim\%((\a\+)\)\=:E553/
lfirst
endtry
endfunction
nnoremap <silent> <Plug>LocationPrevious :<C-u>exe 'call <SID>LocationPrevious()'<CR>
nnoremap <silent> <Plug>LocationNext :<C-u>exe 'call <SID>LocationNext()'<CR>
nmap <silent> ,, <Plug>LocationPrevious
nmap <silent> .. <Plug>LocationNext
"}}}"}}}
" 10. Filetypes {{{
au filetype python nnoremap <F4> :w <bar> exec '!python '.shellescape('%')<CR>
au filetype c nnoremap <F4> :w <bar> exec '!gcc '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
au filetype cpp nnoremap <F4> :w <bar> exec '!g++ '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
au BufRead,BufNewFile *.asm set filetype=nasm
" CUDA
au BufNewFile,BufRead *.cu set filetype=cuda
au BufNewFile,BufRead *.cuh set filetype=cuda
"}}}
" 11. Plugin-specific configuration {{{
" Clang-format {{{
let g:clang_format#command= os == "Darwin" ? '/usr/local/bin/clang-format' : '/usr/bin/clang-format'
" let g:clang_format#code_style='google'
let g:clang_format#style_options = {
\ "BasedOnStyle": "LLVM",
\"IndentWidth": 8,
\"UseTab": "Always",
\"BreakBeforeBraces": "Linux",
\"AllowShortIfStatementsOnASingleLine": "false",
\"IndentCaseLabels": "false"}
" }}}
" CtrlP {{{
map <leader>gh :CtrlP ~<CR>
map <leader>gv :CtrlPMRU<CR>
map <leader>gb :CtrlPBuffer<CR>
" }}}
" ctrlp-funky "{{{
let g:ctrlp_funky_matchtype = 'path'
nnoremap <C-O> :CtrlPFunky<Cr>
let g:ctrlp_funky_syntax_highlight = 1
"}}}
" Man pages using ConqueTerm {{{
let g:ConqueTerm_StartMessages = 0
function! ConqueMan()
let cmd = &keywordprg . ' '
if cmd ==# 'man ' || cmd ==# 'man -s '
if v:count > 0
let cmd .= v:count . ' '
else
let cmd = 'man '
endif
endif
let cmd .= expand('<cword>')
execute 'ConqueTermSplit' cmd
endfunction
map K :<C-U>call ConqueMan()<CR>
ounmap K
" }}}
" NERDCommenter {{{
" Pad comment delimeters with spaces {{{
let NERDSpaceDelims = 1
" }}}
" Map Ctrl+/ to toggle comments "{{{
map <C-\> <Plug>NERDCommenterToggle<CR>
imap <C-\> <Esc><Plug>NERDCommenterToggle<CR>
map <C-_> <Plug>NERDCommenterToggle<CR>
imap <C-_> <Esc><Plug>NERDCommenterToggle<CR>
"}}}
" }}}
" NERDTree "{{{
" Open a NERDTree automatically when vim starts up if no files were specified
" au StdinReadPre * let s:std_in=1
" au VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Key mappings
silent! nmap <C-i> :NERDTreeToggle<CR>
silent! map <F2> :NERDTreeFind<CR>
let g:NERDTreeMapActivateNode="<F2>"
let g:NERDTreeMapPreview="<F3>"
au FileType nerdtree nmap <buffer> <left> u
au FileType nerdtree nmap <buffer> <right> u
" Set the working directory to the current file's directory
au BufEnter * lcd %:p:h
map <leader>ff :NERDTreeFind<cr>
"}}}
" neco-ghc {{{
" Disable haskell-vim omnifunc
let g:haskellmode_completion_ghc = 0
autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
let g:necoghc_enable_detailed_browse = 1
let g:ycm_semantic_triggers = {'haskell' : ['.']}
" }}}
" Tagbar toggle "{{{
nmap <F7> :TagbarToggle<CR>