-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_vimrc
3244 lines (2939 loc) · 128 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 built-in configuration
" Allow settings that are not vi-compatible
if &compatible | set nocompatible | endif
" Reset autocommands when vimrc is re-sourced
augroup VimrcAutocmds
autocmd!
augroup END
" Check if in read-only mode to disable unnecessary plugins
if !exists('s:readonly') | let s:readonly = &readonly || exists('vimpager') | endif
" Make sure $MYVIMRC gets set
if empty($MYVIMRC) | let $MYVIMRC = expand('<sfile>') | endif
set shiftwidth=4 " Number of spaces to indent
set expandtab " Use spaces instead of tabs
set softtabstop=4
set autoindent " Automatic indentation
set cinoptions+=N-s " Don't indent namespaces in C++
set cinoptions+=:0 " Don't indent inside switch statement
set nowrap " Don't wrap lines
set encoding=utf-8 " Set default file encoding
set backspace=indent,eol,start " Backspace through everything in insert mode
set whichwrap+=<,>,[,] " Cursor keys wrap to previous/next line
set hlsearch " Highlight search terms
set incsearch " Incremental searching
set ignorecase " Make search case-insensitive and smart
set smartcase
set noshowmode " Don't show current mode
set nrformats-=octal " Don't treat numbers as octal when incrementing/decrementing
set shortmess+=t " Truncate filenames in messages when necessary
sil! set shortmess+=c " Don't display insert completion messages
set showmatch " Show matching brace after inserting
set scrolloff=2 " Pad lines/columns with context around cursor
set sidescrolloff=5
set display+=lastline " Show as much as possible of the last line in a window
set autoread " Automatically load file if changed outside of vim
set number " Turn on hybrid line numbers
sil! set relativenumber
set history=5000 " Remember more command history
set tabpagemax=20 " Allow more tabs
set hidden " Allow switching buffer without saving changes first
set wildmenu " Turn on autocompletion
set wildmode=longest:full,full
set visualbell " Use visual bell instead of sound
sil! set undofile " Enable persistent undo
set undolevels=1000
sil! set undoreload=10000
set ttimeout " Make keycodes time out after a short delay
set ttimeoutlen=50
set laststatus=2 " Always show statusline
set keywordprg=:help " Use Vim help instead of man to look up keywords
set splitright " Vertical splits open on the right
set fileformats=unix,dos " Always prefer unix format
sil! set fileformat=unix
set csqf=s-,c-,d-,i-,t-,e- " Use quickfix list for cscope results
set foldopen+=jump " Jumps open folds
set clipboard=unnamed " Yank to system clipboard
sil! set clipboard+=unnamedplus
set mouse= " Disable mouse integration
set cmdwinheight=15 " Increase command window height
sil! set showbreak=↪\ " Show character at start of wrapped lines
set nojoinspaces " Don't add two spaces after punctuation
set gdefault " Substitute all occurrences by default
set nostartofline " Don't jump to start of line for various motions
set isfname+={,} " Interpret {} as part of a filename
set isfname-== " but not =
sil! set breakindent " Indent wrapped lines
set tags-=./tags tags^=./tags; " Search upwards for tags
set complete=.,w,t " Don't complete from non-visible buffers
set diffopt+=vertical " Open diffs in vertical splits
sil! set inccommand=nosplit " Preview substitute commands
" Ignore system files
set wildignore=*.a,*.lib,*.spi,*.sys,*.dll,*.so,*.o,.DS_Store,*.pyc,*.d,*.exe,*.hi,*.pkl,*.ipynbc
set suffixes&vim
let &suffixes .= ','.substitute(&wildignore, '*', '', 'g')
" Configure display of whitespace
sil! set listchars=tab:▸\ ,trail:·,extends:»,precedes:«,nbsp:×,eol:¬
" Cursor: block in normal/visual, vertical in insert/command, horizontal in replace/operator pending
if has('nvim')
let &guicursor = 'n-v-c-sm:block-blinkwait1000-blinkon500-blinkoff500,'
\ . 'i-c-ci-ve:ver25-blinkwait1000-blinkon500-blinkoff500,'
\ . 'r-cr-o:hor20-blinkwait1000-blinkon500-blinkoff500'
endif
" Turn on filetype plugins and indent settings
filetype plugin indent on
" Turn on syntax highlighting
if !exists("syntax_on") | syntax enable | endif
" Use four spaces to indent vim file line continuation
let g:vim_indent_cont=4
" Session settings
set sessionoptions=buffers,curdir,help,tabpages,winsize
nnoremap <silent> ,l :source ~/session.vis<CR>
if !s:readonly && !exists('g:no_session')
augroup VimrcAutocmds
au VimLeavePre * mks! ~/session.vis
au VimEnter * mks! ~/periodic_session.vis
au VimEnter * exe "au BufWinEnter * silent! mks! ~/periodic_session.vis"
augroup END
endif
" Enable matchit plugin
if has('nvim')
runtime! plugin/matchit.vim
else
runtime! macros/matchit.vim
endif
execute 'onoremap <silent> V%' substitute(maparg('%', 'o'), '^v', 'V', '')
execute 'onoremap <silent> Vg%' substitute(maparg('g%', 'o'), '^v', 'V', '')
" Disable built-in man plugin
let g:loaded_man = 1
" {{{ Switch to last active tab/window
let g:lastTab=1
func! s:LastActiveWindow() " {{{
if winnr('#') > 0 && winnr('#') != winnr()
wincmd p
elseif winnr('$') > 1
wincmd w
elseif tabpagenr() != g:lastTab && g:lastTab <= tabpagenr('$')
execute "tabnext ".g:lastTab
else
tabnext
endif
endfunc " }}}
autocmd VimrcAutocmds TabLeave * let g:lastTab=tabpagenr()
nnoremap <silent> <expr> ` <SID>inCmdWin()? ':q<CR>' : ':call <SID>LastActiveWindow()<CR>'
xnoremap <silent> ` :<C-u>call <SID>LastActiveWindow()<CR>
nnoremap <silent> <Leader>l :exe "tabn ".g:lastTab<CR>
nnoremap <silent> <Leader>; :exe "tabn ".g:lastTab<CR>
nnoremap <silent> ' `
xnoremap <silent> ' `
nnoremap <silent> <M-'> '
xnoremap <silent> <M-'> '
for s:num in range(1, 10)
execute printf('nnoremap <Leader>%d %dgt', s:num % 10, s:num)
endfor
" }}}
" {{{ Platform-specific configuration
let hasMac=has("mac")
let hasWin=has("win16") || has("win32") || has("win64")
let hasSSH=!empty($SSH_CLIENT)
let mobileSSH=hasSSH && $MOBILE == 1
if hasWin
" Change where backups are saved
if !isdirectory("C:\\temp\\vimtmp")
call mkdir("C:\\temp\\vimtmp", "p")
endif
set backupdir=C:\temp\vimtmp,.
set directory=C:\temp\vimtmp//,.
" Explore to current file
nnoremap <silent> <F4> :call system('start explorer /select,\"'.expand('%:p').'\"')<CR>
" Use Cygwin shell if present
if system('where zsh') =~? 'zsh'
set shell=zsh
elseif system('where bash') =~? 'bash'
set shell=bash
else
" Reset v:shell_error
call system('echo')
endif
if &shell !~ 'cmd'
set shellxquote=\" shellcmdflag=-c shellslash grepprg=grep\ -nH\ $*\ /dev/null
nnoremap <silent> <F4> :call system('cygstart explorer /select,\"'
\.substitute(expand('%:p'),'\/','\\','g').'\"')<CR>
endif
let s:hasvimtools=filereadable(expand("$VIM/vimfiles/autoload/vimtools.vim"))
else
" Change swap file location for unix
if !isdirectory(expand("~/.tmp"))
call mkdir(expand("~/.tmp"), "p")
endif
set backupdir=~/.tmp,.
set directory=~/.tmp//,.
sil! set undodir=.,~/.tmp
if hasMac
" Reveal current file in Finder
nnoremap <silent> <F4> :<C-u>call system('reveal '.fnameescape(expand('%:p')))<CR>
" Enable use of option key as meta key
sil! set macmeta
else
" Explore to current file from Cygwin vim
nnoremap <silent> <F4> :call
\ system('cygstart explorer /select,`cygpath -w "'.expand('%:p').'"`')<CR>
" Use cygstart to open links
let g:netrw_browsex_viewer = "cygstart"
endif
let s:hasvimtools=filereadable(expand("$HOME/.vim/autoload/vimtools.vim"))
endif
" }}}
" {{{ Mappings
" Save current file if modified or execute command if in command window
nn <silent> <expr> <C-s> <SID>inCmdWin()? '<CR>' : ':<C-u>update<CR>'
ino <silent> <expr> <C-s> <SID>inCmdWin()? '<CR>' : '<Esc>:<C-u>update<CR>'
vn <silent> <C-s> <C-c>:<C-u>update<CR>
snor <silent> <C-s> <C-c>:<C-u>update<CR>
" Redraw the screen, remove search highlighting, and synchronize syntax
if v:version > 704 || (v:version == 704 && has('patch79'))
nn <silent> <expr> <C-l> v:hlsearch ? ':<C-u>nohlsearch<CR>' : '<C-l>'
endif
nm <silent> g<C-l> :<C-u>syntax sync fromstart<CR><C-l>
" Execute q macro
nm Q @q
" Toggle paste mode
nn <silent> <Leader>pp :set paste!<CR>
" Select all
nn <Leader>a ggVG
vn <Leader>a <Esc>ggVG
" Toggle line numbers
nn <silent> <F2> :set number!<Bar>silent! let &relativenumber=&number<CR>
vm <silent> <F2> <Esc><F2>gv
im <F2> <C-o><F2>
" Edit configuration files
if s:hasvimtools
command! -nargs=1 SwitchToOrOpen call vimtools#SwitchToOrOpen(<f-args>)
else
command! -nargs=1 SwitchToOrOpen tab drop <args>
endif
let g:file_dict = {
\ 'a': '$HOME/.vim/after/plugin/after.vim',
\ 'b': ['$HOME/.bashrc', '$HOME/.bash_history'],
\ 'c': '$HOME/.cshrc',
\ 'd': '$HOME/.dircolors',
\ 'f': '$HOME/.fzf.zsh',
\ 'G': '$HOME/.ghci',
\ 'g': ['$HOME/.gitconfig', '$HOME/.gitconfig_local'],
\ 'H': '$HOME/.haskeline',
\ 'h': ['$HOME/.histfile', '$HOME/.directory_history'],
\ 'i': '$HOME/.inputrc',
\ 'j': '$HOME/.jupyter/jupyter_console_config.py',
\ 'l': '$HOME/.zshrclocal',
\ 'M': '$HOME/.minttyrc',
\ 'm': '$HOME/.matplotlib/matplotlibrc',
\ 'n': '$HOME/.config/nvim/init.vim',
\ 'P': '$HOME/.plugged',
\ 'p': ['$HOME/.ipython/profile_default/ipython_config.py',
\ '$VIMCONFIG/misc/python/ipython_config.py'],
\ 's': '$HOME/.screenrc',
\ 't': ['$HOME/.tmux.conf', '$HOME/.tmux-local.conf'],
\ 'u': '$HOME/.muttrc',
\ 'v': [has('nvim') ? '$HOME/.vimrc' : '$MYVIMRC',
\ '$HOME/.vim/after/plugin/after.vim'],
\ 'x': '$HOME/.Xdefaults',
\ 'z': ['$HOME/.zshrc', '$HOME/.zshrclocal'],
\ }
for key in keys(g:file_dict)
execute 'nnoremap <silent> ,e'.key.' :<C-u>call <SID>edit_dotfile("'.key.'")<CR>'
endfor
func! s:simplify(file) abort " {{{
return resolve(expand(a:file))
endfunc " }}}
func! s:escape(file) abort " {{{
return fnameescape(s:simplify(a:file))
endfunc " }}}
func! s:edit_dotfile(key) abort " {{{
if type(g:file_dict[a:key]) == type([])
if v:count == 2 || s:simplify(expand('%:p')) == s:simplify(g:file_dict[a:key][0])
execute 'edit '.s:escape(g:file_dict[a:key][1]).'|normal! zv'
else
execute 'edit '.s:escape(g:file_dict[a:key][0]).'|normal! zv'
endif
else
execute 'edit '.s:escape(g:file_dict[a:key]).'|normal! zv'
endif
endfunc " }}}
" Source vimrc
nn <silent> ,sv :so $MYVIMRC<CR>:runtime after/plugin/after.vim<CR>
" Shortcuts for switching buffer
nn <silent> <C-p> :bp<CR>
nn <silent> <C-n> :bn<CR>
" Search recursively or non-recursively
nn ,gr :vim // **/*<C-Left><C-Left><Right>
nn ,gn :vim // *<C-Left><C-Left><Right>
nn ,go :call setqflist([])<CR>:silent! Bufdo! vimgrepa // %<C-Left><C-Left><Right>
nn <Leader>gr :grep **/*(D.) -e ''<Left>
nn <Leader>gn :grep *(D.) -e ''<Left>
nn <Leader>go :call setqflist([])<CR>:silent! Bufdo! grepa '' %<C-Left><C-Left><Right>
" Delete trailing whitespace
nn <silent> <expr> ,ws ':keepj keepp sil! %s/\s\+$//'.(&gdefault ? '' : 'g').'<CR>'
" Open tag vertically or below
nn <silent> <C-w><C-]> :<C-u>belowright vertical split<CR><C-]>zv
nn <silent> <C-w>] :<C-u>belowright split<CR><C-]>zv
nn <silent> <C-w>g<C-]> :<C-u>tab split<CR><C-]>zv
xn <silent> <C-w><C-]> :<C-u>belowright vertical split<CR>gv<C-]>zv
xn <silent> <C-w>] :<C-u>belowright split<CR>gv<C-]>zv
" Shortcuts for switching tab, including closing command window if it's open
nn <silent> <expr> <C-Tab> tabpagenr('$')==1 ?
\":sil! call system('tmux next')\<CR>" : (<SID>inCmdWin()? ':q<CR>gt' : 'gt')
nn <silent> <expr> <C-S-Tab> tabpagenr('$')==1 ?
\":sil! call system('tmux prev')\<CR>" : (<SID>inCmdWin()? ':q<CR>gT' : 'gT')
cno <silent> <expr> <C-Tab> system('tmux next')
cno <silent> <expr> <C-S-Tab> system('tmux prev')
vno <silent> <expr> <C-Tab> system('tmux next')
vno <silent> <expr> <C-S-Tab> system('tmux prev')
nm <M-l> <C-Tab>
nm <M-h> <C-S-Tab>
map <F15> <C-Tab>
map <F16> <C-S-Tab>
map! <F15> <C-Tab>
map! <F16> <C-S-Tab>
" Open new tab
nn <silent> <M-t> <C-u>:$tabnew<CR>
nn <silent> <M-T> <C-u>:$tab split<CR>
" Delete without yank by default, and <M-d> or \\d for delete with yank
if maparg('c', 'n') == ''
for k in ['c', 'd', 's', 'x', 'C', 'D', 'S', 'X']
for m in ['nnoremap', 'xnoremap']
exe m.' '.k.' "_'.k.'|'.m.' <M-'.k.'> '.k.'|'.m.' \\'.k.' '.k.'|ono <M-'.k.'> '.k
endfor
endfor
endif
" Copy file/path with/without line number
function! s:copy(arg) abort " {{{
let @+ = a:arg | let @* = @+ | let @" = @+
echo 'copied: ' . @"
endfunction " }}}
nn <silent> <C-g> <C-g>:let @+ = expand('%:p')<CR>:let @* = @+<CR>:let @" = @+<CR>
nn <silent> g<C-g> g<C-g>:let @+ = expand('%:p:h')<CR>:let @* = @+<CR>:let @" = @+<CR>
nn <silent> 1<C-g> 1<C-g>:call <SID>copy(expand('%:p:t'))<CR>
nn <silent> <M-g> <C-g>:call <SID>copy(expand('%:p').':'.line('.'))<CR>
nn <silent> <M-G> <C-g>:call <SID>copy(expand('%:p:t').':'.line('.'))<CR>
" Change tab position
nn <silent> <C-w><C-e> :tabm<CR>
nn <silent> <C-w>e :tabm<CR>
nn <silent> <C-w><C-a> :tabm0<CR>
nn <silent> <C-w>a :tabm0<CR>
nn <silent> <C-w><C-Left> :<C-u>exe 'tabm-'.v:count1<CR>
nn <silent> <C-w><Left> :<C-u>exe 'tabm-'.v:count1<CR>
nn <silent> <C-w><C-Right> :<C-u>exe 'tabm+'.v:count1<CR>
nn <silent> <C-w><Right> :<C-u>exe 'tabm+'.v:count1<CR>
" Make <C-c> cancel <C-w> instead of closing window
no <C-w><C-c> <NOP>
" Make <C-w><C-q>/<C-w>q close window except the last window
nn <silent> <expr> <C-w><C-q> <SID>inCmdWin()? ':q<CR>' : '<C-w>c'
nn <silent> <expr> <C-w>q <SID>inCmdWin()? ':q<CR>' : '<C-w>c'
nn <silent> <expr> <C-w><C-w> <SID>inCmdWin()? ':q<CR>' : '<C-w><C-w>'
" <M-k>/<M-j> deletes blank line above/below
nn <silent> <M-j> m`:sil +g/\m^\s*$/d<CR>``:noh<CR>:call
\ histdel("search",-1)<CR>:let @/=histget("search",-1)<CR>
nn <silent> <M-k> m`:sil -g/\m^\s*$/d<CR>``:noh<CR>:call
\ histdel("search",-1)<CR>:let @/=histget("search",-1)<CR>
" Backspace deletes visual selection
vn <BS> "_d
" Ctrl-c copies visual characterwise
vn <C-c> <Esc>'<0v'>g_y
" File explorer at current buffer with -
nn <silent> - :Explore<CR>
" Repeat last command with a bang
nn @! :<C-u><C-r><C-r>:<Home><C-Right>!<CR>
" Repeat last command with case of first character switched
nn @~ :<C-u><C-r><C-r>:<C-f>^~<CR>
" Repeat last command with 'verbose' prepended
nn @& :<C-u><C-r><C-r>:<Home>verbose <CR>
nn @? :<C-u><C-r><C-r>:<Home>verbose <CR>
" Use <C-q> to do what <C-v> used to do
no <C-q> <C-v>
" Show current line of diff at bottom of tab
nn <Leader>dl <C-w>t<C-w>s<C-w>J<C-w>t<C-w>l<C-w>s<C-w>J<C-w>t:res<CR><C-w>b
" Make Y behave like other capital letters
nn Y y$
" Navigate windows with arrow keys
no <Down> <C-w>j
no <Up> <C-w>k
no <Left> <C-w>h
no <Right> <C-w>l
" Change window size with control + arrow keys
no <silent> <C-Down> :<C-u>call vimtools#ResizeWindow('down')<CR>
no <silent> <C-Up> :<C-u>call vimtools#ResizeWindow('up')<CR>
no <silent> <C-Left> :<C-u>call vimtools#ResizeWindow('left')<CR>
no <silent> <C-Right> :<C-u>call vimtools#ResizeWindow('right')<CR>
" Stay in visual mode after indent change
vn < <gv
vn > >gv
" Copy WORD/word above/below cursor with (<C-y>/<C-f>)/(<M-y>/<M-f>)
ino <silent> <C-f> <C-r>=matchstr(getline(line('.') + 1), '\v%'.virtcol('.').'v%(\S+\|\s*)')<CR>
ino <silent> <C-y> <C-r>=matchstr(getline(line('.') - 1), '\v%'.virtcol('.').'v%(\S+\|\s*)')<CR>
ino <silent> <M-f> <C-r>=matchstr(getline(line('.') + 1), '\v%'.virtcol('.').'v%(\k+\|\W)')<CR>
ino <silent> <M-y> <C-r>=matchstr(getline(line('.') - 1), '\v%'.virtcol('.').'v%(\k+\|\W)')<CR>
ino <M-F> <C-e>
ino <M-Y> <C-y>
" Make j/k work as expected on wrapped lines
no <expr> j &wrap && strdisplaywidth(getline('.')) > (winwidth(0) -
\ (&number ? &numberwidth : 0)) ? 'gj' : 'j'
no <expr> k &wrap && max([strdisplaywidth(getline('.')),
\ strdisplaywidth(getline(line('.')-1))]) >
\ (winwidth(0) - (&number ? &numberwidth : 0)) ? 'gk' : 'k'
" ZZ and ZQ close buffer if it's not open in another window
nn <silent> <expr> ZQ substitute('%sdelete")<CR>:normal! ZQ<CR>%s'.&bufhidden.
\ '")<CR>','%s',':<C-u>call setbufvar('.bufnr('%').',"\&bufhidden","','g')
nn <silent> <expr> ZZ substitute('%sdelete")<CR>:normal! ZZ<CR>%s'.&bufhidden.
\ '")<CR>','%s',':<C-u>call setbufvar('.bufnr('%').',"\&bufhidden","','g')
" Save and quit all
nn <silent> ZA :wqall<CR>
" Go up directory tree easily
cno <expr> . (getcmdtype()==':'&&getcmdline()=~'[/ ]\.\.$')?'/..':'.'
" Execute line under cursor
if s:hasvimtools
nno <silent> <Leader>x :<C-u>let g:first_op=1<bar>set opfunc=vimtools#SourceMotion<CR>g@
nno <silent> <Leader>xx :<C-u>set opfunc=vimtools#SourceMotion<Bar>exe
\ 'norm! 'v:count1.'g@_'<CR>
autocmd VimrcAutocmds FileType vim ino <silent> <buffer> <Leader>x <Esc>:<C-u>let g:first_op=1
\ <bar>set opfunc=vimtools#SourceMotion<Bar>exe 'norm! 'v:count1.'g@_'<CR>
autocmd VimrcAutocmds FileType help,vim xno <silent> <buffer> <C-p> :<C-u>
\ call SaveRegs()<CR>gvy:execute 'PP <C-r>=substitute(@@, "'", '&&', 'g')<CR>'
\ <bar>call RestoreRegs()<CR>
xno <silent> <Leader>x :<C-u>call vimtools#SourceMotion('visual')<CR>
else
nn <silent> <Leader>xx :exec getline('.')<CR>
endif
" Close quickfix window/location list
nn <silent> <Leader>w :cclose<bar>Windo lclose<bar>pclose<CR>
" Switch to quickfix or location list window
nn <silent> <C-w><Space> :copen<CR>
nn <silent> <C-w><C-Space> :copen<CR>
nn <silent> <C-w><C-@> :copen<CR>
nn <silent> <C-w><C-g><Space> :lopen<CR>
nn <silent> <C-w><C-g><C-Space> :lopen<CR>
nn <silent> <C-w><C-g><C-@> :lopen<CR>
nn <silent> <C-w>g<Space> :lopen<CR>
nn <silent> <C-w>g<C-Space> :lopen<CR>
nn <silent> <C-w>g<C-@> :lopen<CR>
" Make current buffer a scratch buffer
nn <silent> <Leader>ss :<C-u>set buftype=<C-r>=&buftype ==# 'nofile' ? '' : 'nofile'<CR><CR>
" Echo syntax name under cursor
nn <silent> <Leader>y :<C-U>exe vimtools#EchoSyntax(v:count)<CR>
" Change directory
nn <silent> <Leader>cd :execute "Windo cd ".fnameescape(
\ &filetype ==# 'vimfiler' ? b:vimfiler.current_dir : expand('%:p:h'))<CR>:echo getcwd()<CR>
nn <silent> ,cd :lcd %:p:h<CR>:pwd<CR>
nn <silent> <Leader>.. :execute "Windo cd ".fnameescape(fnamemodify(getcwd(),':h'))<bar>pwd
\ <bar>silent! call repeat#set("\<Leader>..")<CR>
nn <silent> ,.. :lcd ..<CR>:pwd<CR>:sil! call repeat#set(",..")<CR>
" Put from " register in insert mode
ino <M-p> <C-r>"
" Go to older position in jump list
nn <S-Tab> <C-o>zv
" Make <C-d>/<C-u> scroll 1/3 page
no <expr> <C-d> (v:count ? "" : (winheight('.')) / 3 + 1)."\<C-d>"
no <expr> <C-u> (v:count ? "" : (winheight('.')) / 3 + 1)."\<C-u>"
" Highlight word without moving cursor
nn <Leader>* :<C-u>let @/ = '\<' . expand('<cword>') . '\>'<bar>
\ call histadd('/', @/)<bar>set hlsearch<bar>echo '/' . @/<CR>zv
nmap <Leader>8 <Leader>*
nn <Leader>g* :<C-u>let @/ = expand('<cword>')<bar>
\ call histadd('/', @/)<bar>set hlsearch<bar>echo '/' . @/<cr>zv
nmap <Leader>g8 <Leader>g*
" Move current line to 1/5 down from top or up from bottom
nn <expr> zh "zt".(winheight('.')/5)."\<C-y>"
nn <expr> zl "zb".(winheight('.')/5)."\<C-e>"
xn <expr> zh "zt".(winheight('.')/5)."\<C-y>"
xn <expr> zl "zb".(winheight('.')/5)."\<C-e>"
" Open cursor file in vertical or horizontal split
nn <silent> <C-w><C-f> :belowright vertical wincmd f<CR>
nn <silent> <C-w>f :belowright wincmd f<CR>
xn <silent> <C-w><C-f> :<C-u>belowright vertical split<CR>gvgf
xn <silent> <C-w>f :<C-u>belowright vertical split<CR>gvgf
" Default make key
nn <silent> <F5> :update<CR>:make<CR><CR>
nn <silent> g<F5> :update<CR>:make clean<CR><CR>
im <F5> <Esc><F5>
" Cycle through previous searches
nn <silent> <expr> <C-k> (<SID>inCmdWin()? '' : "/\<C-f>".(v:count1 + 1))."k:let @/=getline('.')<CR>"
nn <silent> <expr> <C-j> <SID>inCmdWin()? "j:let @/=getline('.')<CR>" : '<C-j>'
" Don't open fold when jumping to first or last line in diff mode and remember G jumps
nn <silent> <expr> gg "gg".(&diff ? "" : "zv")
nn <silent> <expr> G "G".(&diff ? "" : "zv") . (v:count ? 'mGmg' : '')
" [count]V/v always selects [count] lines/characters
nn <expr> V v:count ? "\<Esc>V".(v:count > 1 ? (v:count - 1).'j' : '') : 'V'
nn <expr> v v:count ? "\<Esc>v".(v:count > 1 ? (v:count - 1).'l' : '') : 'v'
" <Home> moves cursor after \v
cno <expr> <Home> "\<Home>".(getcmdtype() =~ '[/?]' &&
\ getcmdline() =~? '^\\v' ? "\<Right>\<Right>" : "")
cmap <C-b> <Home>
" Fix @: in visual mode when there is a modifier before the range
vnoremap <expr> @ @: =~ "\\V'<,'>" ? "\<Esc>@" : "@"
" Synonym for q:
nn g: q:
" Use <C-n>/<C-p> instead of arrows for command line history
cm <C-p> <Up>
cm <C-n> <Down>
" - is used for file browser
nn _ -
xn _ -
" Go to most recent text change
nn <silent> g. m':silent! execute "buffer".g:last_change_buf<CR>:keepjumps normal! `.<CR>
" Delete swap file and reload file
nn <silent> <Leader>ds :<C-u>if delete(b:swapname) == 0<bar>set noreadonly<bar>else<bar>
\ echoerr 'failed to delete swapfile'<bar>endif<CR>
" Until opening pair, comma, or semicolon
ono . :<C-u>call search('[[({<,;]')\|echo<CR>
xno . <Esc>`>l:call search('[[({<,;]')\|echo<CR>v`<oh
ono g] vg_
xno g] g_h
" Update diff
nn <silent> du :<C-u>diffupdate<CR>
" Insert home directory after typing $~
ino <expr> ~ getline('.')[col('.')-2] == '$' ? "\<BS>".$HOME : '~'
cno <expr> ~ getcmdline()[getcmdpos()-2] == '$' ? "\<BS>".$HOME : '~'
" Discard changes and reload undofile for current file
nn <silent> <Leader><Leader>r :<C-u>execute "silent later ".&undolevels
\<bar>while &modified<bar>silent earlier<bar>endwhile
\<bar>execute 'rundo '.fnameescape(undofile(expand('%:p')))<CR>
" Don't save omaps to command history
silent! nn <unique> . .
" New line when cursor is not at the end of the current line
ino <silent> <C-j> <Space><BS><C-r>="\<lt>C-o>o"<CR>
vno <C-j> <Esc>o
ino <silent> <C-k> <Space><BS><C-r>="\<lt>C-o>O"<CR>
vno <C-k> <Esc>O
" Insert filename tail with <C-r>$ and escape special characters with <C-r>%/#
cno <expr> <C-r>% fnameescape(expand('%'))
cno <expr> <C-r># fnameescape(expand('#'))
cno <expr> <C-r>$ fnameescape(expand('%:t'))
ino <expr> <C-r>$ expand('%:t')
" Equivalent of 'dgn' for all matches in buffer/visual selection
nn <silent> <Leader>dgn :<C-u>%s///<CR>
xn <silent> gd :s///<CR>
" Faster repeat of previous shell command
cno <expr> ! getcmdtype() == ':' && getcmdline() == '!' ? '!<CR>' : '!'
" Move cursor in insert mode without splitting undo
ino <Left> <C-g>U<Left>
ino <Right> <C-g>U<Right>
function! s:home() abort " {{{
let line = getline('.')
let before = strchars(line[:col('.')-1]) - 1
let after = strchars(line[col('.')-1:])
let blanks = strchars(matchstr(line, '^\s*'))
if before < blanks
return repeat("\<C-g>U\<Right>", blanks - before)
elseif before == blanks
return repeat("\<C-g>U\<Left>", blanks)
else
return repeat("\<C-g>U\<Left>", before - blanks + (after ? 0 : 1))
endif
endfunction " }}}
inoremap <expr> <Home> <SID>home()
inoremap <expr> <End> repeat("<C-g>U<Right>", strchars(getline('.')[col('.')-1:]))
im <C-b> <Home>
im <C-e> <End>
" Remove trailing whitespace with <CR> (<BS> can delete multiple characters so use <Del>)
augroup insert_cr
autocmd!
autocmd InsertEnter,InsertLeave,VimEnter * let g:insert_cr_valid = 1
autocmd InsertCharPre * let g:insert_cr_valid = g:insert_cr_valid && v:char == "\<CR>"
augroup END
function! s:InsertCR(repeat) abort " {{{
if a:repeat && !exists('s:insert_cr_after')
let s:insert_cr_after = @.[stridx(@., "\n") + 1:]
elseif !a:repeat
silent! unlet s:insert_cr_after
endif
if getline('.')[:col('.') - 2] =~? '\v(\S|^)\s+$'
let l:dels = repeat("\<Left>\<Del>", len(matchstr(getline('.')[:col('.') - 2], '\s\+$')))
else
let l:dels = ''
endif
if g:insert_cr_valid
let g:insert_cr_valid = 0
silent! call repeat#set("\<Plug>InsertCR")
return l:dels . "\<CR>" . (a:repeat ? s:insert_cr_after : '')
else
return l:dels . (pumvisible() ? "\<C-y>" : '') . "\<CR>"
endif
endfunction " }}}
inoremap <expr> <Plug>InsertCR <SID>InsertCR(0)
nnoremap <expr> <Plug>InsertCR g:insert_cr_valid ? 'i' . <SID>InsertCR(1) . "\<Esc>zv" : "\<CR>zv"
imap <CR> <Plug>InsertCR
inoremap \<CR> \<CR>
" Make * and # use 'smartcase'
nn * /\<<C-r>=expand('<cword>')<CR>\><CR>zv
nn # ?\<<C-r>=expand('<cword>')<CR>\><CR>zv
nn g* /<C-r>=expand('<cword>')<CR><CR>zv
nn g# ?<C-r>=expand('<cword>')<CR><CR>zv
" Toggle IPython history storage
nn <silent> ,ih :<C-u>let g:ipython_store_history = !get(g:, 'ipython_store_history', 1)<CR>
\:<C-u>echo 'IPython history ' . (g:ipython_store_history ? 'enabled' : 'disabled')<CR>
" Insert date
ino <silent> <expr> <C-x><C-d> substitute(strftime('%d%b%Y'), '^0*', '', '')
cno <expr> <C-x><C-d> substitute(strftime('%d%b%Y'), '^0*', '', '')
ino <silent> <expr> <C-x>d strftime('%Y_%m_%d_%H%M%Z')
cno <expr> <C-x>d strftime('%Y_%m_%d_%H%M%Z')
" Copy all differences from other buffer
nn <Leader>do <C-\><C-n>gg:diffget<bar>1,$+diffget<CR>
" Shortcuts for t_ and T_
omap _ t_
omap - T_
" }}}
" {{{ Abbreviations to open help
if s:hasvimtools
command! -nargs=? -complete=help Help call vimtools#OpenHelp(<q-args>)
cnorea <expr> ht getcmdtype()==':'&&getcmdpos()<=3 ? 'tab help':'ht'
cnorea <expr> h getcmdtype()==':'&&getcmdpos()<=2 ? 'Help':'h'
cnorea <expr> H getcmdtype()==':'&&getcmdpos()<=2 ? 'Help':'H'
cnoremap <expr> <Up> getcmdtype()==':'&&getcmdline()=='h' ? '<BS>H<Up>':'<Up>'
nmap <silent> <expr> K <SID>inCmdWin()? 'viwK' : ":exec
\ 'Help '.vimtools#HelpTopic()<CR>"
vnoremap <silent> <expr> K vimtools#OpenHelpVisual()
endif
" }}}
" {{{ Cscope configuration
" Mappings for cscope find commands
no <M-\>s :cs find s <C-r>=expand("<cword>")<CR><CR>
no <M-\>g :cs find g <C-r>=expand("<cword>")<CR><CR>
no <M-\>c :cs find c <C-r>=expand("<cword>")<CR><CR>
no <M-\>t :cs find t <C-r>=expand("<cword>")<CR><CR>
no <M-\>e :cs find e <C-r>=expand("<cword>")<CR><CR>
no <M-\>f :cs find f <C-r>=expand("<cfile>")<CR><CR>
no <M-\>i :cs find i ^<C-r>=expand("<cfile>")<CR>$<CR>
no <M-\>d :cs find d <C-r>=expand("<cword>")<CR><CR>
vm <M-\> <Esc><M-\>
" }}}
" {{{ Functions
" Save/restore unnamed/clipboard registers
func! SaveRegs() " {{{
let s:quotereg = @" | let s:starreg = @* | let s:plusreg = @+
endfunc " }}}
func! RestoreRegs() " {{{
let @" = s:quotereg | let @* = s:starreg | let @+ = s:plusreg
endfunc " }}}
" Like bufdo but return to starting buffer
func! Bufdo(command, bang) " {{{
let currBuff=bufnr("%")
if a:bang
execute 'bufdo set eventignore-=Syntax | ' . a:command
else
execute 'bufdo ' . a:command
endif
execute 'buffer ' . currBuff
endfunc " }}}
command! -nargs=+ -bang -complete=command Bufdo call Bufdo(<q-args>, <bang>0)
" Like windo but restore current and previous window
function! Windo(command) " {{{
call map(range(1, winnr('$')), "
\ setwinvar(v:val, '_winid', v:val == winnr() ? 1 : (v:val == winnr('#') ? 0 : -1))")
execute 'windo' a:command
for id in range(2)
silent! execute filter(range(1, winnr('$')), "
\ getwinvar(v:val, '_winid') == id")[0] 'wincmd w'
endfor
endfunction " }}}
command! -nargs=+ -complete=command Windo call Windo(<q-args>)
" Function to set key codes for terminals
func! s:KeyCodes() " {{{
" Set key codes to work as meta key combinations
for n in range(33, 47) + range(58, 61) + range(63, 90) + range(92, 126)
execute "set <M-" . escape(nr2char(n), '"|') . ">=\<Esc>" . escape(nr2char(n), '"|')
endfor
endfunc " }}}
nnoremap <silent> <Leader>k :call <SID>KeyCodes()<CR>
if mobileSSH && !has('nvim') | call s:KeyCodes() | endif
func! s:CmdwinMappings() " {{{
" Make gf/<C-]> work in command window
function! s:cmdwinmap(map, exp, cmd) abort " {{{
return printf('nnoremap <silent> <buffer> %s :let cword = ' .
\ 'expand("<' . a:exp . '>")<CR>:quit<CR>:execute "%s " . cword<CR>zv', a:map, a:cmd)
endfunction " }}}
execute s:cmdwinmap('gf', 'cfile', 'edit')
execute s:cmdwinmap('<C-w><C-f>', 'cfile', 'belowright vsplit')
execute s:cmdwinmap('<C-w>f', 'cfile', 'belowright split')
execute s:cmdwinmap('<C-w>gf', 'cfile', 'tabedit')
execute s:cmdwinmap('<C-]>', 'cword', 'tag')
execute s:cmdwinmap('<C-w><C-]>', 'cword', 'belowright vertical stag')
execute s:cmdwinmap('<C-w>]', 'cword', 'belowright stag')
execute s:cmdwinmap('<C-w>g<C-]>', 'cword', 'tab stag')
execute s:cmdwinmap('g<C-]>', 'cword', 'tjump')
execute s:cmdwinmap('g<C-w><C-]>', 'cword', 'belowright vertical stjump')
execute s:cmdwinmap('g<C-w>]', 'cword', 'belowright stjump')
execute s:cmdwinmap('g<C-w>g<C-]>', 'cword', 'tab stjump')
" Delete item under cursor from history
nnoremap <silent> <buffer> dD :call histdel(g:cmdwinType,'\V\^'.
\escape(getline('.'),'\').'\$')<CR>:norm! "_dd<CR>
" Resize window
nnoremap <buffer> <C-Up> <C-w>+
nnoremap <buffer> <C-Down> <C-w>-
" Close window
nnoremap <silent> <buffer> <Leader>w :q<CR>
nnoremap <silent> <buffer> ZZ :q<CR>
" Don't delete trailing trailing with <CR> in command window
inoremap <buffer> <expr> <CR> (pumvisible() ? '<C-y>' : '') . '<CR>'
endfunc " }}}
" Delete hidden buffers
func! s:DeleteHiddenBuffers() " {{{
let tpbl=[]
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for l:buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
silent! execute 'bd' l:buf
endfor
endfunc " }}}
nnoremap <silent> <Leader>dh :call <SID>DeleteHiddenBuffers()<CR>
func! s:CleanEmptyBuffers() " {{{
let buffers = filter(range(0, bufnr('$')), 'buflisted(v:val) && '
\.'empty(bufname(v:val)) && bufwinnr(v:val)<0 && getbufvar(v:val,"&buftype")==""')
if !empty(buffers)
exe 'bw '.join(buffers, ' ')
endif
endfunc " }}}
nnoremap <silent> <Leader>de :call <SID>CleanEmptyBuffers()<CR>
" Kludge to make first quickfix result unfold
func! s:ToggleFoldOpen() " {{{
if &fdo != 'all'
let s:fdoOld=&fdo
set ut=1 fdo=all
aug ToggleFoldOpen
au CursorHold * call s:ToggleFoldOpen()
aug END
else
exec 'set fdo='.s:fdoOld.' ut=4000'
aug ToggleFoldOpen
au!
aug END
endif
endfunc " }}}
autocmd VimrcAutocmds QuickFixCmdPost * call s:ToggleFoldOpen()
" Function to redirect output of ex command to clipboard
func! Redir(cmd) " {{{
redir @" | execute a:cmd | redir END
let @"=substitute(@","^\<NL>*",'','g')
let @*=@"
let @+=@"
endfunc " }}}
command! -nargs=+ -complete=command Redir call Redir(<q-args>)
nnoremap <Leader>R :<C-r><C-r>:<Home>Redir <CR>
" Function to removing trailing carriage return from register
func! s:FixReg() " {{{
let l:reg=nr2char(getchar())
let l:str=getreg(l:reg)
while l:str =~ "\<CR>\<NL>"
let l:str=substitute(l:str,"\<CR>\<NL>","\<NL>",'')
endwhile
call setreg(l:reg, l:str)
endfunc " }}}
nnoremap <silent> <Leader>f :call <SID>FixReg()<CR>
" Cycle search mode between regular, very magic, and very nomagic
func! s:CycleSearchMode() " {{{
let l:cmd = getcmdline()
let l:pos = getcmdpos()
if l:cmd =~# '\v(KeepPatterns [sgv]\/)?(\\\%V)?\\v'
let l:cmd = substitute(l:cmd,'\v(KeepPatterns [sgv]\/)?(\\\%V)?\\v','\1\2\\V','')
elseif l:cmd =~# '\v(KeepPatterns [sgv]\/)?(\\\%V)?\\V'
let l:cmd = substitute(l:cmd,'\v(KeepPatterns [sgv]\/)?(\\\%V)?\\V','\1\2','')
call setcmdpos(l:pos - 2)
else
let l:cmd = substitute(l:cmd,'\v(^.*KeepPatterns [sgv]\/)?(\\\%V)?','\1\2\\v','')
call setcmdpos(l:pos + 2)
endif
return l:cmd
endfunc " }}}
cnoremap <expr> <C-x><C-x> getcmdtype() =~ '[/?:]' ?
\ "\<C-\>e\<SID>CycleSearchMode()\<CR>" : ""
" Close other windows or close other tabs
func! s:CloseWinsOrTabs() " {{{
let startwin = winnr()
wincmd t
if winnr() == winnr('$')
tabonly
else
if winnr() != startwin | wincmd p | endif
wincmd o
endif
endfunc " }}}
nnoremap <silent> <C-w>o :call <SID>CloseWinsOrTabs()<CR>
nnoremap <silent> <C-w><C-o> :call <SID>CloseWinsOrTabs()<CR>
" <C-v> pastes from system clipboard
func! s:Paste() " {{{
if @+ =~ "\<NL>"
set paste
set pastetoggle=<F10>
return "\<C-r>+\<F10>".(@+=~"\<NL>$"?"\<BS>":"")
endif
return "\<C-r>+"
endfunc " }}}
nnoremap <C-v> "+gP
cnoremap <expr> <C-v> getcmdtype() == '=' ?
\ "\<C-r>+" : "\<C-r>=substitute(@+, '\\n', '', 'g')\<CR>"
imap <expr> <C-v> <SID>Paste()
exe 'vnoremap <silent> <script> <C-v> '.paste#paste_cmd['v']
" Make last search a whole word
func! s:SearchWholeWord(dir) " {{{
let sf = v:searchforward
if @/[0:1] ==# '\v'
let @/ = '\v<('.@/[2:].')>'
elseif @/[0:1] ==# '\V'
let @/ = '\V\<\('.@/[2:].'\)\>'
else
let @/='\<\('.@/.'\)\>'
endif
call histadd('/', @/)
if (a:dir && sf) || (!a:dir && !sf)
echo '/'.@/ | return '/'."\<CR>"
else
echo '?'.@/ | return "?\<CR>"
endif
endfunc " }}}
nn <silent> <expr> <Leader>n <SID>SearchWholeWord(1).'zv'
nn <silent> <expr> <Leader>N <SID>SearchWholeWord(0).'zv'
" Search for first non-blank
func! s:FirstNonBlank() " {{{
if getcmdline() == '^'
return "\<BS>".'\(^\s*\)\@<='
elseif getcmdline() ==# '\v^'
return "\<BS>".'(^\s*)@<='
elseif getcmdline() ==# '\V^'
return "\<BS>".'\(\^\s\*\)\@\<\='
else
return '^'
endif
endfunc " }}}
cnoremap <expr> ^ getcmdtype()=~'[/?]' ? <SID>FirstNonBlank() : '^'
" Don't delete the v/V at the start of a search
func! s:SearchCmdDelWord() " {{{
let s:iskeyword = &l:iskeyword | setlocal iskeyword&
let cmd = (getcmdtype() =~ '[/?]' ? '/' : '').
\ strpart(getcmdline(), 0, getcmdpos() - 1)
if cmd =~# '\v/%(\\\%V)?\\[vV]\k+\s*$'
return "\<C-w>".matchstr(cmd, '\v/%(\\\%V)?\\\zsv\ze\k*\s*$')
elseif cmd =~# '\v/\\\%V\k+\s*$'
return "\<C-w>V"
endif
return "\<C-w>"
endfunc
func! s:ResetIskeyword()
let &l:iskeyword = s:iskeyword
return ''
endfunc " }}}
cnoremap <expr> <C-w> <SID>SearchCmdDelWord() . '<C-r>=<SID>ResetIskeyword()<CR>'
cnoremap <expr> <C-u> "\<C-u>".
\ ((getcmdtype() =~ '[/?]' && len(getcmdline()) > 2 &&
\ (getcmdline()[:1] == '\v' \|\| getcmdline()[:1] == '\V')) ? getcmdline()[:1] : '')
" <C-Left> moves cursor after \v
func! s:SearchCtrlLeft() " {{{
if getcmdtype() =~ '[/?]' && getcmdline() =~? '^\\v'
if strpart(getcmdline(), 0, getcmdpos() - 1) =~ '\v^\S+\s?$'
return "\<C-Left>\<Right>\<Right>"
endif
endif
return "\<C-Left>"
endfunc " }}}
cnoremap <expr> <C-Left> <SID>SearchCtrlLeft()
" Fix up arrow in search history when search starts with \v
func! s:OlderHistory() " {{{
augroup omap_slash
autocmd!
augroup END
if getcmdtype() =~ '[/?]' && getcmdline() ==? '\v'
return "\<C-u>\<Up>"
elseif getcmdtype() == ':' && getcmdline() =~# '\v^.*[Ssgv]/\\[vV]$'
return "\<BS>\<BS>\<Up>"
elseif getcmdtype() == ':' && getcmdline() =~# '\v^.*[Ssgv]/\\\%V\\[vV]$'
return repeat("\<BS>", 5)."\<Up>"
elseif s:hasvimtools && getcmdtype() == ':' && getcmdline() == 'h'
return "\<BS>H\<Up>"
elseif getcmdline() == ''
return "\<S-Up>"
endif
return "\<Up>"
endfunc " }}}
cnoremap <expr> <Up> <SID>OlderHistory()
" Add wildcards to path in command line for zsh-like expansion
func! s:StarifyPath() " {{{
set wildcharm=<C-t>
let cmdline = getcmdline()
let space = match(cmdline, '\m^.*\zs\s\ze\S\+$')
let start = cmdline[0:space]
let finish = substitute(cmdline[space+1:-1],'[^[:space:]~]\zs/','*/','g')
return start.finish
endfunc " }}}
cnoremap <C-s> <C-\>e<SID>StarifyPath()<CR><C-t><C-d>
" Ring system bell
func! s:Bell() " {{{
let visualbell_save = &visualbell
set novisualbell
execute "normal! \<Esc>"
let &visualbell = visualbell_save
endfunc " }}}
autocmd VimrcAutocmds QuickFixCmdPost * call s:Bell()
" Setup for single-file C/C++ projects
func! s:SingleFile() " {{{
execute 'setlocal makeprg=make\ '.expand('%:r')