-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvimrc
2195 lines (2002 loc) · 63.8 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:
if &compatible
" vint: -ProhibitSetNoCompatible
set nocompatible
" vint: +ProhibitSetNoCompatible
endif
" =============================================================================
" Requirement Checks: {{{
" =============================================================================
function! s:VersionRequirement(val, min)
for idx in range(0, len(a:min) - 1)
let v = get(a:val, idx, 0)
if v < a:min[idx]
return 0
elseif v > a:min[idx]
return 1
endif
endfor
return 1
endfunction
if has('nvim') && executable('pyenv')
if executable($HOME . '/.pyenv/versions/neovim2/bin/python')
let g:python_host_prog = $HOME . '/.pyenv/versions/neovim2/bin/python'
endif
if executable($HOME . '/.pyenv/versions/neovim3/bin/python')
let g:python3_host_prog = $HOME . '/.pyenv/versions/neovim3/bin/python'
endif
endif
if has('python3') && !has('patch-8.1.201')
silent! python3 1
endif
if !empty(&runtimepath)
let s:vimfiles = split(&runtimepath, ',')[0]
else
echohl ErrorMsg
echomsg 'Unable to determine runtime path for Vim.'
echohl NONE
endif
" }}}
" =============================================================================
" Vim Plug: {{{
" =============================================================================
filetype off
" Install vim-plug if it isn't installed
function! s:DownloadVimPlug()
if !exists('s:vimfiles')
return
endif
if empty(glob(s:vimfiles . '/autoload/plug.vim'))
let plug_url = 'https://github.com/junegunn/vim-plug.git'
let tmp = tempname()
let new = tmp . '/plug.vim'
try
let out = system(printf('git clone --depth 1 %s %s', plug_url, tmp))
if v:shell_error
echohl ErrorMsg
echomsg 'Error downloading vim-plug: ' . out
echohl NONE
return
endif
if !isdirectory(s:vimfiles . '/autoload')
call mkdir(s:vimfiles . '/autoload', 'p')
endif
call rename(new, s:vimfiles . '/autoload/plug.vim')
finally
if isdirectory(tmp)
let dir = '"' . escape(tmp, '"') . '"'
silent call system((has('win32') ? 'rmdir /S /Q ' : 'rm -rf ') . dir)
endif
endtry
endif
endfunction
" Install missing plugins
function! s:InstallMissingPlugins()
if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) |
PlugInstall --sync
endif
endfunction
call s:DownloadVimPlug()
call plug#begin(s:vimfiles . '/plugged')
" -----------------------------------------------------------------------------
" Colorscheme
" -----------------------------------------------------------------------------
Plug 'yous/vim-open-color'
" -----------------------------------------------------------------------------
" General
" -----------------------------------------------------------------------------
if !exists('+fixendofline')
" Preserve missing EOL at the end of text files
Plug 'yous/PreserveNoEOL', {
\ 'commit': '9ef2f01',
\ 'frozen': 1 }
endif
" EditorConfig plugin for Vim
Plug 'editorconfig/editorconfig-vim'
" A Plugin to show a diff, whenever recovering a buffer
Plug 'chrisbra/Recover.vim'
" obsession.vim: continuously updated session files
Plug 'tpope/vim-obsession'
if has('timers') && exists('v:exiting')
" Fix CursorHold Performance
Plug 'antoinemadec/FixCursorHold.nvim'
endif
" Ultimate hex editing system with Vim
Plug 'Shougo/vinarise.vim'
" Vim sugar for the UNIX shell commands
Plug 'tpope/vim-eunuch'
" the missing window movement
if exists('*win_screenpos') || exists('nvim_win_get_position')
Plug 'andymass/vim-tradewinds'
endif
" Vim plugin to diff two directories
Plug 'will133/vim-dirdiff'
" Vim: file and hunk folding support for diff/patch files.
Plug 'sgeb/vim-diff-fold'
" A Vim plugin to copy text through SSH with OSC52
Plug 'ojroques/vim-oscyank'
" A Vim plugin that manages your tag files
if executable('ctags') || executable('cscope')
if v:version >= 800
Plug 'ludovicchabant/vim-gutentags'
elseif v:version >= 704
Plug 'ludovicchabant/vim-gutentags', { 'branch': 'vim7' }
endif
endif
" Vim Git runtime files
Plug 'tpope/vim-git'
" Git wrapper
Plug 'tpope/vim-fugitive'
" A git commit browser
" Plug 'tpope/vim-fugitive' |
Plug 'junegunn/gv.vim'
" -----------------------------------------------------------------------------
" Browsing
" -----------------------------------------------------------------------------
if !has('win32') && (!has('win32unix') || executable('go'))
" A command-line fuzzy finder written in Go
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
endif
" Directory viewer for Vim
Plug 'justinmk/vim-dirvish'
if !has('win32')
" Git support for dirvish.vim
Plug 'kristijanhusak/vim-dirvish-git'
endif
if !has('nvim') && !has('patch-8.1.1218')
" Tab-specific directories
Plug 'vim-scripts/tcd.vim'
endif
" Go to Terminal or File manager
Plug 'justinmk/vim-gtfo'
" -----------------------------------------------------------------------------
" Completion and lint
" -----------------------------------------------------------------------------
" Intellisense engine for Vim8 & Neovim, full language server protocol support
" as VSCode
if executable('node')
if has('nvim-0.8.0') || !has('nvim') && has('patch-9.0.0438')
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
elseif has('nvim-0.4.0') || !has('nvim') && has('patch-8.1.1719')
Plug 'neoclide/coc.nvim', { 'commit': 'f0ce9ae' } " v0.0.82
elseif has('nvim-0.3.2') || !has('nvim') && has('patch-8.0.1453')
Plug 'neoclide/coc.nvim', { 'commit': 'be514c7' } " v0.0.81
endif
endif
" Print documents in echo area
if exists('v:completed_item') && exists('v:event')
Plug 'Shougo/echodoc.vim'
endif
if has('nvim') && has('timers') ||
\ has('timers') && exists('*job_start') && exists('*ch_close_in')
" Asynchronous Lint Engine
Plug 'dense-analysis/ale'
else
" Syntax checking plugin
Plug 'vim-syntastic/syntastic'
endif
" -----------------------------------------------------------------------------
" Motions and text changing
" -----------------------------------------------------------------------------
" Autocomplete if end
Plug 'tpope/vim-endwise'
" Lightning fast left-right movement in Vim
Plug 'unblevable/quick-scope'
" More useful word motions for Vim
Plug 'chaoren/vim-wordmotion'
" The matchit plugin from Vim
Plug 'chrisbra/matchit'
" Python matchit support
Plug 'voithos/vim-python-matchit', { 'for': 'python' }
" Bullets.vim is a Vim/NeoVim plugin for automated bullet lists.
Plug 'dkarter/bullets.vim'
" Auto close (X)HTML tags
Plug 'alvan/vim-closetag', {
\ 'for': ['html', 'javascript.jsx', 'php', 'xhtml', 'xml'] }
" Simplify the transition between multiline and single-line code
Plug 'AndrewRadev/splitjoin.vim'
" The set of operator and textobject plugins to search/select/edit sandwiched
" textobjects
Plug 'machakann/vim-sandwich'
" Pairs of handy bracket mappings
Plug 'tpope/vim-unimpaired'
if v:version == 704 && !has('patch754') || v:version < 704 && v:version >= 700
" Produce increasing/decreasing columns of numbers, dates, or daynames
Plug 'vim-scripts/VisIncr'
endif
" Switch between source files and header files
Plug 'vim-scripts/a.vim'
" Enable repeating supported plugin maps with "."
Plug 'tpope/vim-repeat'
" -----------------------------------------------------------------------------
" Vim UI
" -----------------------------------------------------------------------------
" A light and configurable statusline/tabline for Vim
Plug 'itchyny/lightline.vim'
" Highlight the exact differences, based on characters and words
Plug 'rickhowe/diffchar.vim'
if !has('patch-8.1.1270') && !has('nvim-0.4.0')
" vim-searchindex: display number of search matches & index of a current match
Plug 'google/vim-searchindex'
endif
if has('patch-8.0.1206') || has('nvim-0.2.3')
" Range, pattern and substitute preview for Vim
Plug 'markonm/traces.vim'
elseif v:version >= 703
" :substitute preview
Plug 'osyo-manga/vim-over'
endif
" Simpler Rainbow Parentheses
Plug 'junegunn/rainbow_parentheses.vim', { 'for': [
\ 'clojure',
\ 'lisp',
\ 'racket',
\ 'scheme'] }
if has('patch-8.0.902') || has('nvim')
" Show a diff using Vim its sign column.
Plug 'mhinz/vim-signify'
elseif has('signs')
" Show a git diff in the gutter and stages/reverts hunks
Plug 'airblade/vim-gitgutter'
endif
" zoomwintab vim plugin
Plug 'troydm/zoomwintab.vim', { 'on': 'ZoomWinTabToggle' }
" Distraction-free writing in Vim
Plug 'junegunn/goyo.vim', { 'on': 'Goyo' }
" color hex codes and color names
Plug 'chrisbra/Colorizer'
" -----------------------------------------------------------------------------
" Support file types
" -----------------------------------------------------------------------------
" AdBlock
Plug 'yous/adblock-filter.vim', { 'for': 'adblockfilter' }
" Aheui
Plug 'yous/aheui.vim', { 'for': 'aheui' }
" GNU As
Plug 'HealsCodes/vim-gas', { 'for': 'gas' }
" LaTeX
Plug 'lervag/vimtex', { 'for': ['bib', 'tex'] }
" Markdown
Plug 'godlygeek/tabular', { 'for': 'markdown' } |
Plug 'preservim/vim-markdown', { 'for': 'markdown' }
" PHP
Plug 'vim-scripts/php.vim-html-enhanced', { 'for': ['html', 'php'] }
if v:version >= 700
" ANSI escape sequences concealed, but highlighted as specified (conceal)
Plug 'powerman/vim-plugin-AnsiEsc', { 'for': 'railslog' }
endif
" Rake
Plug 'tpope/vim-rake'
" RBS
Plug 'pocke/rbs.vim'
" reStructuredText
Plug 'habamax/vim-rst', { 'for': 'rst' }
" RuboCop
Plug 'ngmy/vim-rubocop', { 'on': 'RuboCop' }
" smali
Plug 'kelwin/vim-smali', { 'for': 'smali' }
" SMT-LIB
Plug 'raichoo/smt-vim', { 'for': 'smt' }
" Vader
Plug 'junegunn/vader.vim', { 'for': 'vader' }
" A solid language pack for Vim
let g:polyglot_disabled = [
\ 'latex', 'markdown', 'rst',
\ 'autoindent', 'sensible']
Plug 'sheerun/vim-polyglot'
" -----------------------------------------------------------------------------
" macOS
" -----------------------------------------------------------------------------
if has('mac') || has('macunix')
" Add plist editing support to Vim
Plug 'darfink/vim-plist'
endif
call plug#end()
" Followings are done by `plug#end()`:
" filetype plugin indent on
" syntax on
" }}}
" =============================================================================
" General: {{{
" =============================================================================
if &shell =~# 'fish$'
set shell=sh
endif
if has('gui_running')
language messages en
if has('multi_byte')
set encoding=utf-8
scriptencoding utf-8
endif
endif
set autoread
set background=dark
set backspace=indent,eol,start
" Don't make a backup before overwriting a file
set nobackup
" Use the clipboard register '*'
set clipboard=unnamed
if has('unnamedplus')
" Use X11 CLIPBOARD selection
set clipboard=unnamedplus
endif
" How keyword completion works when CTRL-P and CTRL-N are used
" i: scan current and included files
set complete-=i
if has('mac') && $VIM ==# '/usr/share/vim'
set diffopt-=internal
elseif has('patch-8.1.0360')
set diffopt+=algorithm:patience
endif
if !isdirectory(s:vimfiles . '/swap')
call mkdir(s:vimfiles . '/swap', 'p')
endif
" List of directory names for the swap file, separated with commas
execute 'set directory^=' . s:vimfiles . '/swap//'
if has('multi_byte')
set fileencodings=ucs-bom,utf-8,cp949,latin1
endif
set fileformats=unix,mac,dos
if exists('+fixendofline')
" When writing a file and this option is on, <EOL> at the end of file will be
" restored if missing
set nofixendofline
endif
if has('folding')
" Sets 'foldlevel' when starting to edit another buffer in a window
set foldlevelstart=99
endif
" Number of remembered ":" commands
set history=1000
" Ignore case in search
set ignorecase
if has('extra_search')
" Show where the pattern while typing a search command
set incsearch
endif
" Don't redraw the screen while executing macros, registers and other commands
" that have not been typed
set lazyredraw
" Enable list mode
set list
" Strings to use in 'list' mode and for the :list command
try
set listchars=tab:→\ ,trail:·,extends:»,precedes:«,nbsp:~
catch /^Vim\%((\a\+)\)\=:E474/
set listchars=tab:>\ ,trail:_,extends:>,precedes:<,nbsp:~
endtry
" The key sequence that toggles the 'paste' option
set pastetoggle=<F2>
if has('mksession')
" Changes the effect of the :mksession command
set sessionoptions-=buffers " hidden and unloaded buffers
endif
" Help to avoid all the hit-enter prompts caused by file messages and to avoid
" some other messages
" m: use "[+]" instead of "[Modified]"
" r: use "[RO]" instead of "[readonly]"
" c: don't give ins-completion-menu messages
" S: do not show search count message when searching, e.g. "[1/5]"
set shortmess+=m
set shortmess+=r
set shortmess+=c
if has('patch-8.1.1270')
set shortmess-=S
endif
" Override the 'ignorecase' if the search pattern contains upper case
set smartcase
set spellcapcheck=
" Exclude East Asian characters from spell checking
set spelllang-=cjk
set spelllang+=cjk
if exists('+spelloptions')
set spelloptions+=camel
endif
" Files with these suffixes get a lower priority when multiple files match a
" wildcard
set suffixes+=.git,.hg,.svn
set suffixes+=.bmp,.gif,.jpeg,.jpg,.png
set suffixes+=.dll,.exe
set suffixes+=.swo
set suffixes+=.DS_Store
set suffixes+=.pyc
" Filenames for the tag command, separated by spaces or commas
if has('path_extra')
set tags-=./tags
set tags-=./tags;
set tags^=./tags;
endif
if !isdirectory(s:vimfiles . '/undo')
call mkdir(s:vimfiles . '/undo', 'p')
endif
" List of directory names for undo files, separated with commas
execute 'set undodir^=' . s:vimfiles . '/undo//'
" Automatically saves undo history to an undo file when writing a buffer to a
" file, and restores undo history from the same file on buffer read
set undofile
" Maximum number of changes that can be undone
set undolevels=1000
if !has_key(g:plugs, 'FixCursorHold.nvim')
" Update swap file and trigger CursorHold after 100ms
set updatetime=100
endif
if exists('+wildignorecase')
" Ignore case when completing file names and directories
set wildignorecase
endif
if has('wildmenu')
" Enhanced command-line completion
set wildmenu
endif
if has('win32')
if exists('+completeslash')
" A forward slash is used for path completion in insert mode
set completeslash=slash
else
" Use a forward slash when expanding file names
set shellslash
endif
endif
" C
let g:c_comment_strings = 1
" Rust
if executable('rustfmt')
let g:rustfmt_autosave = 1
endif
" TeX
let g:tex_conceal = 'abdmg'
let g:tex_flavor = 'latex'
" }}}
" =============================================================================
" Vim UI: {{{
" =============================================================================
try
colorscheme open-color
catch /^Vim\%((\a\+)\)\=:E185/
colorscheme default
set background=dark
endtry
if has('syntax') && (has('gui_running') || &t_Co > 16)
" Highlight the screen line of the cursor
set cursorline
endif
" Show as much as possible of the last line
set display+=lastline
" Show unprintable characters as a hex number
set display+=uhex
if has('extra_search')
set hlsearch
endif
" Always show a status line
set laststatus=2
" Don't consider octal number when using the CTRL-A and CTRL-X commands
set nrformats-=octal
set number
set scrolloff=3
if has('cmdline_info')
" Show command in the last line of the screen
set showcmd
endif
" Briefly jump to the matching one when a bracket is inserted
set showmatch
" The minimal number of columns to scroll horizontally
set sidescroll=1
set sidescrolloff=10
if exists('+smoothscroll')
" Scrolling works with screen lines
set smoothscroll
endif
if has('windows')
set splitbelow
endif
if has('vertsplit')
set splitright
endif
if empty($STY) && get(g:, 'colors_name', 'default') !=# 'default'
" See https://gist.github.com/XVilka/8346728.
if $COLORTERM =~# 'truecolor' || $COLORTERM =~# '24bit'
if has('termguicolors')
" :help xterm-true-color
if $TERM =~# '^screen'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors
endif
endif
endif
augroup ColorColumn
autocmd!
if exists('+colorcolumn')
" Highlight column after 'textwidth'
set colorcolumn=+1
else
autocmd BufWinEnter *
\ let w:m2 = matchadd('ErrorMsg', '\%' . (&textwidth + 1) . 'v', -1)
endif
augroup END
" Highlight trailing whitespace
function! s:MatchExtraWhitespace(enabled)
if a:enabled && index(['GV', 'vim-plug'], &filetype) < 0
match ExtraWhitespace /\s\+$/
else
match ExtraWhitespace //
endif
endfunction
highlight link ExtraWhitespace Error
augroup ExtraWhitespace
autocmd!
autocmd BufWinEnter * call s:MatchExtraWhitespace(1)
autocmd FileType * call s:MatchExtraWhitespace(1)
autocmd InsertEnter * call s:MatchExtraWhitespace(0)
autocmd InsertLeave * call s:MatchExtraWhitespace(1)
if v:version >= 702
autocmd BufWinLeave * call clearmatches()
endif
augroup END
function! s:UnderlineSpellBad()
highlight clear SpellBad
highlight SpellBad cterm=underline gui=underline
endfunction
call s:UnderlineSpellBad()
augroup UnderlineSpellBad
autocmd!
autocmd ColorScheme * call s:UnderlineSpellBad()
autocmd Syntax * syntax spell toplevel
augroup END
" }}}
" =============================================================================
" GUI: {{{
" =============================================================================
if has('gui_running')
set guifont=Consolas:h10:cANSI
set guioptions+=! " External commands are executed in a terminal window
set guioptions-=e " Tab pages
set guioptions-=m " Menu bar
set guioptions-=t " Tearoff menu items
set guioptions-=T " Toolbar
set guioptions-=r " Right-hand scrollbar
set guioptions-=L " Left-hand scrollbar when window is vertically split
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
if has('win32')
set guifontwide=D2Coding:h10:cDEFAULT,
\NanumGothicCoding:h10:cDEFAULT,
\DotumChe:h10:cDEFAULT
endif
function! s:ScreenFilename()
if has('amiga')
return 's:.vimsize'
elseif has('win32')
return $HOME . '\_vimsize'
else
return $HOME . '/.vimsize'
endif
endfunction
function! s:ScreenRestore()
" Restore window size (columns and lines) and position
" from values stored in vimsize file.
" Must set font first so columns and lines are based on font size.
let f = s:ScreenFilename()
if has('gui_running') && g:screen_size_restore_pos && filereadable(f)
let vim_instance =
\ (g:screen_size_by_vim_instance == 1 ? (v:servername) : 'GVIM')
for line in readfile(f)
let sizepos = split(line)
if len(sizepos) == 5 && sizepos[0] == vim_instance
silent! execute 'set columns=' . sizepos[1] . ' lines=' . sizepos[2]
silent! execute 'winpos ' . sizepos[3] . ' ' . sizepos[4]
return
endif
endfor
endif
endfunction
function! s:ScreenSave()
" Save window size and position.
if has('gui_running') && g:screen_size_restore_pos
let vim_instance =
\ (g:screen_size_by_vim_instance == 1 ? (v:servername) : 'GVIM')
let data = vim_instance . ' ' . &columns . ' ' . &lines . ' ' .
\ (getwinposx() < 0 ? 0: getwinposx()) . ' ' .
\ (getwinposy() < 0 ? 0: getwinposy())
let f = s:ScreenFilename()
if filereadable(f)
let lines = readfile(f)
call filter(lines, "v:val !~ '^" . vim_instance . "\\>'")
call add(lines, data)
else
let lines = [data]
endif
call writefile(lines, f)
endif
endfunction
if !exists('g:screen_size_restore_pos')
let g:screen_size_restore_pos = 1
endif
if !exists('g:screen_size_by_vim_instance')
let g:screen_size_by_vim_instance = 1
endif
augroup ScreenRestore
autocmd!
autocmd VimEnter *
\ if g:screen_size_restore_pos == 1 |
\ call s:ScreenRestore() |
\ endif
autocmd VimLeavePre *
\ if g:screen_size_restore_pos == 1 |
\ call s:ScreenSave() |
\ endif
augroup END
augroup NoCursorMoveOnFocus
autocmd!
autocmd FocusLost *
\ let s:oldmouse = &mouse |
\ set mouse=
autocmd FocusGained *
\ if get(s:, 'oldmouse', '') !=# '' |
\ let &mouse = s:oldmouse |
\ unlet s:oldmouse |
\ endif
augroup END
endif
" }}}
" =============================================================================
" Text Formatting: {{{
" =============================================================================
set autoindent
if has('cindent')
set cindent
" Sets how Vim performs indentation
" lN: If N != 0 Vim will align with a case label instead of the statement
" after it in the same line
" gN: Place C++ scope declarations N characters from the indent of the block
" they are in
" hN: Place statements occurring after a C++ scope declaration N characters
" from the indent of the label
" tN: Indent a function return type declaration N characters from the margin
" (N: When in unclosed parentheses, indent N characters from the line with the
" unclosed parentheses
" When N is 0 or the unclosed parentheses is the first non-white character
" in its line, line up with the next non-white character after the
" unclosed parentheses
" WN: When in unclosed parentheses and N is non-zero and either using "(0" or
" "u0", respectively and the unclosed parentheses is the last non-white
" character in its line and it is not the closing parentheses, indent the
" following line N characters relative to the outer context (i.e. start of
" the line or the next unclosed parentheses)
" kN: When in unclosed parentheses which follow "if", "for" or "while" and N
" is non-zero, overrides the behaviour defined by "(N": causes the indent
" to be N characters relative to the outer context (i.e. the line where
" "if", "for" or "while" is)
set cinoptions=l1,g0.5s,h0.5s,t0,(0,W2s,k2s
endif
set expandtab
" Insert only one space after a '.', '?' and '!' with a join command
set nojoinspaces
" Number of spaces to use for each step of (auto)indent
set shiftwidth=2
" <Tab> in front of a line inserts blanks according to 'shiftwidth'
set smarttab
" Number of spaces that a <Tab> counts for while editing
" Use the value of 'shiftwidth'
set softtabstop=-1
" Number of spaces that a <Tab> in the file counts for
set tabstop=8
" Maximum width of text that is being inserted
set textwidth=80
augroup TextFormatting
autocmd!
autocmd FileType asm,gitconfig,kconfig
\ setlocal noexpandtab shiftwidth=8
" Show utf-8 glyphs for TeX
autocmd FileType bib,tex setlocal conceallevel=1
" Reload .editorconfig because of heuristic detections done by vim-polyglot
autocmd FileType c,cpp,perl
\ setlocal shiftwidth=4 |
\ if has_key(g:plugs, 'editorconfig-vim') |
\ execute 'EditorConfigReload' |
\ endif
autocmd FileType go
\ setlocal noexpandtab shiftwidth=4 tabstop=4
" Plain view for plugins
autocmd FileType GV,vim-plug
\ setlocal colorcolumn= nolist textwidth=0
autocmd FileType java,json
\ setlocal shiftwidth=4
autocmd FileType make
\ let &l:shiftwidth = &l:tabstop
autocmd FileType python
\ setlocal shiftwidth=4 textwidth=79
" t: Auto-wrap text using textwidth
" c: Auto-wrap comments using textwidth
" r: Automatically insert the current comment leader after hitting <Enter> in
" Insert mode
" o: Automatically insert the current comment leader after hitting 'o' or 'O'
" in Normal mode
" q: Allow formatting of comments with "gq"
" l: Long lines are not broken in insert mode
" j: Remove a comment leader when joining lines
autocmd FileType *
\ setlocal formatoptions+=c
\ formatoptions+=r
\ formatoptions+=q
\ formatoptions+=l |
\ if &filetype ==# 'markdown' |
\ setlocal formatoptions+=o |
\ else |
\ setlocal formatoptions-=o |
\ endif |
\ if index(['gitcommit',
\ 'gitsendemail',
\ 'markdown',
\ 'tex'], &filetype) < 0 |
\ setlocal formatoptions-=t |
\ endif |
\ if v:version >= 704 || v:version == 703 && has('patch541') |
\ setlocal formatoptions+=j |
\ endif
augroup END
" }}}
" =============================================================================
" Mappings: {{{
" =============================================================================
" Commander
nnoremap ; :
nnoremap <Space> ;
" We do line wrap
noremap j gj
noremap k gk
noremap <Down> gj
noremap <Up> gk
noremap gj j
noremap gk k
" Easy navigation on a line
noremap H ^
noremap L $
" Unix shell behavior
inoremap <C-A> <C-C>I
inoremap <expr> <C-E> pumvisible() ? "\<C-E>" : "\<End>"
" Close braces
function! s:CloseBrace()
let line_num = line('.')
let next_line = getline(line_num + 1)
if col('.') != col('$')
return "{\<CR>"
elseif !empty(next_line) &&
\ indent(line_num + 1) == indent(line_num) &&
\ next_line =~# '^\s*}'
return "{\<CR>"
elseif (&filetype ==# 'c' || &filetype ==# 'cpp') &&
\ getline(line_num) =~# '\%(' .
\ '^\s*\%(typedef\s*\)\?\%(class\|enum\|struct\)\s\+' . '\|' .
\ '\<\h\w*\s*=\s*$' . '\)'
return "{\<CR>};\<C-C>O"
else
return "{\<CR>}\<C-C>O"
endif
endfunction
inoremap <expr> {<CR> <SID>CloseBrace()
" Navigate completions
if has_key(g:plugs, 'coc.nvim')
inoremap <silent> <expr> <Tab> coc#pum#visible() ? coc#pum#next(1) :
\ pumvisible() ? "\<C-N>" : "\<Tab>"
inoremap <silent> <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(1) :
\ pumvisible() ? "\<C-P>" : "\<S-Tab>"
else
inoremap <expr> <Tab> pumvisible() ? "\<C-N>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-P>" : "\<S-Tab>"
endif
" Leave insert mode
function! s:CtrlL()
" Keep the original feature of CTRL-L. See :help i_CTRL-L.
if exists('&insertmode') && &insertmode
call feedkeys("\<C-L>", 'n')
else
call feedkeys("\e", 't')
endif
endfunction
inoremap <silent> <C-L> <C-O>:call <SID>CtrlL()<CR>
" Delete without copying
vnoremap <BS> "_d
nnoremap c "_c
vnoremap c "_c
nnoremap cc "_cc
nnoremap C "_C
" Break the undo block when CTRL-U
inoremap <C-U> <C-G>u<C-U>
if has('wildmenu')
" Move into subdirectory in wildmenu
function! s:WildmenuEnterSubdir()
call feedkeys("\<Down>", 't')
return ''
endfunction
cnoremap <expr> <C-J> <SID>WildmenuEnterSubdir()
endif
" Move cursor between splitted windows
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
" Go to tab page by number
for s:i in range(1, 9)
execute 'nnoremap <Leader>' . s:i . ' ' . s:i . 'gt'
endfor
unlet s:i
nnoremap <Leader>0 :tablast<CR>
" Reselect visual block after shifting
vnoremap < <gv
vnoremap > >gv
" Use CTRL-N to clear the highlighting
nnoremap <silent> <C-N> :<C-U>nohlsearch<C-R>=&diff ? '<Bar>diffupdate' : ''<CR><CR>
" Clear screen
nnoremap <Leader><C-L> <C-L>
" Search for visually selected text
function! s:VSearch(cmd)
let old_reg = getreg('"')
let old_regtype = getregtype('"')
normal! gvy
let pat = escape(@", a:cmd . '\')
let pat = substitute(pat, '\n', '\\n', 'g')
let @/ = '\V' . pat
normal! gV
call setreg('"', old_reg, old_regtype)
endfunction
if has_key(g:plugs, 'vim-searchindex')
vnoremap <silent> * :<C-U>call <SID>VSearch('/')<CR>/<C-R>/<CR>zz<Plug>SearchIndex
vnoremap <silent> # :<C-U>call <SID>VSearch('?')<CR>?<C-R>/<CR>zz<Plug>SearchIndex
else
vnoremap <silent> * :<C-U>call <SID>VSearch('/')<CR>/<C-R>/<CR>zz
vnoremap <silent> # :<C-U>call <SID>VSearch('?')<CR>?<C-R>/<CR>zz
endif
" Center display after searching
if has_key(g:plugs, 'vim-searchindex')
nmap <silent> n nzz<Plug>SearchIndex
nmap <silent> N Nzz<Plug>SearchIndex
nmap <silent> * *zz<Plug>SearchIndex
nmap <silent> # #zz<Plug>SearchIndex
nmap <silent> g* g*zz<Plug>SearchIndex
nmap <silent> g# g#zz<Plug>SearchIndex
else
function! s:CenterBeforeSearch(opposite)
if @/ ==# ''
return
endif
let backward = v:searchforward == a:opposite
let flags = backward ? 'b' : ''
for i in range(v:count1 - 1)
call search(@/, flags)
endfor
let pos = searchpos(@/, flags . 'n')
if pos != [0, 0] && pos[0] != line('.')
if backward
if !(pos[0] == line('$') && pos[1] >= col([line('$'), '$']) - 1)
keepjumps call cursor(pos[0], col([pos[0], '$']) - 1)
normal! zz
if pos[1] >= col([pos[0], '$']) - 1
keepjumps call cursor(pos[0] + 1, 1)
endif
endif
else
if pos != [1, 1]
keepjumps call cursor(pos[0], 1)
normal! zz
if pos[1] == 1
keepjumps call cursor(pos[0] - 1, col([pos[0] - 1, '$']) - 1)
endif
endif
endif
endif
endfunction
nnoremap <silent> n :<C-U>call <SID>CenterBeforeSearch(0)<CR>n
nnoremap <silent> N :<C-U>call <SID>CenterBeforeSearch(1)<CR>N
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#zz
endif
" Execute @q which is recorded by qq
nnoremap Q @q
" Cscope mappings
if has('cscope') && executable('cscope')
function! s:FindCscopeDB()
let db = findfile('cscope.out', '.;')
if !empty(db)
silent cscope reset
silent! execute 'cscope add' db
elseif !empty($CSCOPE_DB)
silent cscope reset
silent! execute 'cscope add' $CSCOPE_DB
endif
endfunction
set cscopetag
set cscopetagorder=0
call s:FindCscopeDB()
" 0 or s: Find this C symbol
" 1 or g: Find this definition
" 2 or d: Find functions called by this function
" 3 or c: Find functions calling this function
" 4 or t: Find this text string
" 6 or e: Find this egrep pattern
" 7 or f: Find this file
" 8 or i: Find files #including this file
" 9 or a: Find places where this symbol is assigned a value
nnoremap <C-\>s :cscope find s <C-R><C-W><CR>
nnoremap <C-\>g :cscope find g <C-R><C-W><CR>
nnoremap <C-\>d :cscope find d <C-R><C-W><CR>
nnoremap <C-\>c :cscope find c <C-R><C-W><CR>
nnoremap <C-\>t :cscope find t <C-R><C-W><CR>