-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
1670 lines (1480 loc) · 53.1 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
"""""""""""""""""""""""""""""" {{{1
" General settings {{{1
""""""""""""""""""""""""" {{{2
set nocompatible " not VI compatible
set history=500 " lines of history to remember
set timeoutlen=700 " shorter timeout for mappings
set ttimeoutlen=100 " shorter timeout for key codes
" info 'for 100 files', 'nothing >100kB', 'nohlsearch'
set viminfo='100,s100,h
set undofile " save undo trees
set undodir=/tmp/$USER/vim,. " try and save undo trees to RAM
if exists("$SHM_D")
let &undodir = $SHM_D."/vim,".&undodir
endif
if exists("*mkdir")
for dir in split(&undodir, '\\\@<!,')
try
if !len(glob(dir))
call mkdir(dir, 'p', 0700)
endif
break
catch /E739/
endtry
endfor
endif
"let &cdpath=substitute($CDPATH, ':', ',', 'g')
""" Pathogen {{{2
" plugins to disable
let g:pathogen_disabled = ["zencoding"]
" python 2/3
if has('python3')
let g:gundo_prefer_python3 = 1
endif
" these require ruby
if ! has("ruby")
call add(g:pathogen_disabled, "lusty")
endif
" diable plugin auto stuff
"let g:jedi#auto_initialization = 0
"let g:jedi#auto_vim_configuration = 0
let g:tsuquyomi_disable_default_mappings = 1
" source and call pathogen
runtime bundle/pathogen/autoload/pathogen.vim
call pathogen#infect()
"call pathogen#runtime_append_all_bundles()
""" helper functions {{{2
" List AddUnique(List lst, Object val) {{{
function! AddUnique(lst, val)
if index(a:lst, a:val) == -1
return add(a:lst, a:val)
endif
return a:lst
endfunction " }}}
" int FirstOf(String|List|Dict haystack, String|List|Dict needles, int start=0) {{{
" Finds the first of the given needles in the haystack.
function! FirstOf(haystack, needles, ...)
if type(a:haystack) == type("")
let Index = function('stridx')
else
let Index = function('index')
endif
let haystack = a:haystack
if type(a:needles) == type([]) || type(a:needles) == type({})
let needles = a:needles
elseif type(a:needles) == type("")
let needles = split(a:needles, '\zs')
else
let needles = [a:needles]
endif
if a:0
let start = a:1
else
let start = 0
endif
let idx = len(haystack)
for needle in needles
let temp = Index(haystack, needle, start)
if temp >= 0 && temp < idx
let idx = temp
endif
endfor
if idx >= len(haystack)
let idx = -1
endif
return idx
endfunction " }}}
" logging style functions
function! Error(...) " {{{
echohl ErrorMsg
echo "Error: " . join(a:000)
echohl None
return 0
endfunction " }}}
function! Warn(...) " {{{
if &verbose >= 1
echohl WarningMsg
echo "Waring: " . join(a:000)
echohl None
endif
return 0
endfunction " }}}
function! Info(...) " {{{
if &verbose >= 2
echo "Info: " . join(a:000)
endif
return 1
endfunction " }}}
" Dictionary fuctions to be used to control dictionary like options {{{3
" (e.g. listchars and fillchars). To use:
" 1. Create a dictionary called [s:][_]optname (no conflict with actual option
" as that looks like &optname, but can prefix with '_' and make script local
" for clarity.
" 2. Create a control dictionary by calling:
" let CNTRL_NAME = deepcopy(_opt_ctrl_dict)._init('DICT_NAME'[, 'process'])
" where DICT_NAME is the [s:][_]optname used above. This initialises the
" control dictionary, and then either by passing the argument 'process',
" calling CNTRL_NAME._process(), or an initial CNTRL_NAME._toggle(...) will
" set the option appropriately.
let _opt_ctrl_dict = {}
function _opt_ctrl_dict._init(...) dict " Initiate control dict {{{
" If given, set name
if a:0 | let self._name = a:1 | endif
" Check for global variable, else assume a script local
if exists(self._name) | let name = self._name
else | let name = 's:' . self._name
endif
" Get dictionaries keys
exec "let keys = keys(" . name . ")"
" Copy the keys
for key in keys
if key[0] != "_"
exec "let self[key] = " . name . "[key]"
endif
endfor
if a:0 >= 2 && a:2 ==? "process"
self._process()
endif
return self
endfunction " }}}
function _opt_ctrl_dict._process() dict " Process control dict {{{
" Get option name (removing leading '_')
if self._name[0] == '_' | let name = '&l:' . self._name[1:]
else | let name = '&l:' . self._name
endif
" Clear option
exec "let " . name . " = ''"
" Set option with 'self's items
for key in keys(self)
if key[0] != "_" && strlen(self[key])
exec "let " . name . " .= key . ':' . self[key] . ','"
endif
endfor
endfunction " }}}
function _opt_ctrl_dict._toggle(...) dict " Toggle key(s) in control dict {{{
" Check for global variable, else assume a script local
if exists(self._name) | let name = self._name
else | let name = 's:' . self._name
endif
" Toggle all arguments given
for key in a:000
if strlen(self[key])
let self[key] = ''
else
exec "let self[key] = " . name . "[key]"
endif
endfor
" Call our process method
call self._process()
endfunction " }}}
" end dictionary functions }}}3
""" Locations {{{2
function! MungePath(...) abort
if ! a:0 | return '' | endif
let sep = ':' | let test = 0
let parts = [] | let a_i = 0
if type(a:1) == v:t_dict
if has_key(a:1, 'sep') | let sep = a:1['sep'] | endif
if has_key(a:1, 'test') | let test = a:1['test'] | endif
let a_i += 1
endif
while a_i < a:0
let arg = a:000[a_i] | let a_i += 1
if type(arg) != v:t_string
throw 'MungePath argument '.a_i.' is not a string: '.string(arg)
endif
for part in split(arg, sep)
let part = fnamemodify(part, ':p')
if index(parts, part) >= 0 | continue | endif
if test && getftype(part) != "dir"
if exists('g:MungePath_debug') && g:MungePath_debug
echoerr "MungePath: part not a dir, ignoring: ".part
endif
continue
endif
call add(parts, part)
endfor
endwhile
return join(parts, sep)
endfunction
""" npm's <project_root>/node_modules/.bin folder
if executable('npm')
" TODO: make this compatible for non-unix
autocmd FileType javascript,typescript silent let $PATH = MungePath(
\ {'test': 1},
\ trim(
\ system("cd ".expand('%:h:S')." >/dev/null && npm root"),
\ "\r\n"
\ ).'/.bin',
\ $PATH
\)
endif
"""""""""""""""""""""""""""""" {{{1
" VIM UI {{{1
""""""""""""""""""""""""" {{{2
""" Look {{{2
set vb t_vb= " disable bell
set ruler " always show ruler (position)
" Customise ruler
let s:_ruler_head = "%=%{winnr()}: %<%.24(%f%)%([%M%H%W%R]%) " " file name and status
if exists("*fugitive#statusline") " fugitive branch info
let s:_ruler_mid = "%.24(%{fugitive#statusline()}%)"
else | let s:_ruler_mid = ""
endif
let s:_ruler_tail = "%=%7(%c%V%)%=,%-6(%l%) %P" " current position
" set rulerformat and statusline so they look identical.
let s:_ruler = s:_ruler_head . s:_ruler_mid . s:_ruler_tail
let &rulerformat = "%80(" . s:_ruler . "%)"
let &statusline = "%=" . s:_ruler . " "
" function to change ruler highlighting FIXME: no local ruler?
function! RulerHighlight(hlGroup)
if hlexists(a:hlGroup) && exists('&rulerformat') && strlen(&rulerformat)
let &l:rulerformat = substitute(&rulerformat,
\ '^\(%\([0-9]\+\)\?\(\.\([0-9]\+\)\?\)\?(\)\?'
\ . '\(%#[^#]*#\)\?\(.*\)$',
\ '\1%#' . a:hlGroup . '#\6', '')
endif
endfunction
"autocmd WinEnter * call RulerHighlight('StatusLine')
"autocmd WinLeave * call RulerHighlight('StatusLineNC')
set laststatus=0 " don't show status line at end
set cmdwinheight=3 " smaller cmdline window
set number " number rows
autocmd Filetype info,man setlocal nonumber
set showtabline=1 " 0:never 1:>1page 2:always
"autocmd Filetype info,man setlocal showtabline=1
set tabpagemax=40 " max number opening tabs = ?
"colorscheme TjlH_col
"colorscheme desert
"colorscheme elflord
" solarized
"if ! has("gui_running")
"let g:solarized_termcolor = 256
"let g:solarized_termtrans = 1
"endif
"call togglebg#map("<Leader><Leader>bg")
"set background=dark
"colorscheme solarized
"unmap <F5>
try
colorscheme desert256-TjlH
catch /^Vim\%((\a\+)\)\=:E185/
colorscheme desert
autocmd ColorScheme *
\ highlight Normal ctermbg=NONE |
\ highlight NonText ctermbg=NONE
endtry
set display+=lastline " show as much of lastline as possible, not '@'s
" Set characters to display for non-printing and fill charaters
if &encoding == 'utf-8'
let s:_listchars = {'eol': '¶', 'tab': '➤∼', 'trail': '⋯',
\ 'extends': '⟫', 'precedes': '⟪',
\ 'conceal': '·', 'nbsp': '∾'}
let s:_fillchars = {'stl': '┴', 'stlnc': '─', 'vert': '│',
\ 'fold': '┄', 'diff': '╶'}
else
let s:_listchars = {'eol': '$', 'tab': '>-', 'trail': '-',
\ 'extends': '>', 'precedes': '<',
\ 'conceal': ' ', 'nbsp': '~'}
let s:_fillchars = {'stl': '^', 'stlnc': '-', 'vert': '|',
\ 'fold': '-', 'diff': '-'}
endif
let _lcs = deepcopy(_opt_ctrl_dict)._init('_listchars') " Init &lcs ctrl dict
let _fcs = deepcopy(_opt_ctrl_dict)._init('_fillchars') " Init &fcs ctrl dict
"let _lcs = deepcopy(s:_listchars) " Get a control copy
"let _fcs = deepcopy(s:_fillchars) " Get a control copy
" Disable some characters initially
call _lcs._toggle('eol', 'conceal')
call _fcs._toggle('stl', 'stlnc')
""" Feel {{{2
set mouse=a " always enable mouse input
set backspace=indent,eol,start " always let <BS> do its thing
" use <Esc> to enter cmd window and again from normal mode to exit it.
set cedit=<Esc>
autocmd CmdwinEnter * nmap <buffer> <silent> <Esc> :quit<CR>
autocmd CmdwinEnter * cmap <buffer> <silent> <Esc> <C-u>quit<CR>
let mapleader = ','
let maplocalleader = '\'
" , is the opposite of ; for moving within a line, don't use it often, but give
" it a mapping so we don't have to wait for timeoutlen
nnoremap ,; ,
" <Esc> is sometimes a pain, but j is easy, and it's very rare you ever need to
" enter it twice in inset.
noremap! jj <Esc>
set scrolloff=4 " keep cursor 5 lines from edge
set sidescroll=8
set sidescrolloff=12
set whichwrap=b,s,>,< " which movement chars move lines
set incsearch " search as type
set ignorecase smartcase " ignore case except explicit UC
set virtualedit+=block " move past EOL in block mode
" make Y like C
noremap Y y$
" map increment and decrement TODO - equivalent for visual mode?
nnoremap ++ <C-a>
nnoremap -- <C-x>
" remove search highlighting
noremap <silent> <Space> :<C-u>nohlsearch<CR>
" 'r'eload (source) 'c'onfiguration file
noremap <Leader>rc :<C-u>source $MYVIMRC<CR>
"autocmd BufWritePost **vimrc !source $MYVIMRC " auto reload vimrc
"autocmd BufWritePost $MYVIMRC : $MYVIMRC
" function to cycle a numeric variable
function! CycleNumber(name, max)
let current = eval(a:name)
let new = (current + 1) % (a:max + 1)
exec "let " . a:name . " = new"
if a:name[0:0]== '&'
echo " " . a:name[1:] . " = " . new
else
echo " " . a:name . " = " . new
endif
endfunction
" set *number toggle mappings
nnoremap <Leader><Leader>nu :let &number = ! &nu<CR>
nnoremap <Leader><Leader>rn :let &relativenumber = ! &rnu<CR>
" set laststatus toggle mappings
nnoremap <Leader><Leader>ls :call CycleNumber("&laststatus", 2)<CR>
" set list[chars] mappings
nnoremap <Leader><Leader>li :let &list = ! &list<CR>
nnoremap <Leader><Leader>lce :call _lcs._toggle("eol")<CR>
nnoremap <Leader><Leader>lct :call _lcs._toggle("tab")<CR>
nnoremap <Leader><Leader>lcl :call _lcs._toggle("trail")<CR>
nnoremap <Leader><Leader>lcx :call _lcs._toggle("extends")<CR>
nnoremap <Leader><Leader>lcp :call _lcs._toggle("precedes")<CR>
nnoremap <Leader><Leader>lcc :call _lcs._toggle("conceal")<CR>
nnoremap <Leader><Leader>lcn :call _lcs._toggle("nbsp")<CR>
" set paste " enable paste INSERT
nnoremap <Leader><Leader>p :let &paste = ! &paste<CR>
" add PYTHONPATH to search path for 'gf' TODO: parse line for import, etc.
"autocmd FileType python let &path=&path.substitute($PYTHONPATH, ':', ',', 'g')
""" Binary edit {{{2
function! s:setup_binary()
if &bin
%!xxd
set ft=xxd
augroup binary
autocmd BufWritePre <buffer> %!xxd -r
autocmd BufWritePost <buffer> %!xxd | set nomod
augroup end
else
echoe "Not &binary"
endif
endfunction
autocmd BufReadPre *.bin setlocal binary
" messes up afterimage: autocmd BufReadPost * call s:setup_binary()
command! -bar Binary call s:setup_binary()
""" Program Execution {{{2
" Make executable / compile
" TODO: set makeprog rather than calling chmod, use writepre, etc.
map <buffer> <Leader>mx :update<Bar>make "%:t:r"<CR>
map <buffer> <Leader>mX :update<CR>:make "%:t:r" <Up>
autocmd Filetype javascript,perl,php,python,ruby,sh
\ map <buffer> <Leader>mx :update<Bar>!chmod +x %<CR>
autocmd Filetype javascript,perl,php,python,ruby,sh
\ map <buffer> <Leader>mX :update<CR>:!chmod <Up>
autocmd Filetype ebuild
\ map <buffer> <Leader>mx :update<Bar>!ebuild "%" manifest<CR>
autocmd Filetype ebuild
\ map <buffer> <Leader>mX :update<CR>:!ebuild "%" <Up>
autocmd Filetype dot
\ map <buffer> <Leader>mx :update<CR>:!dot -Tpng "%"<BAR>display &<CR>
map <buffer> <Leader>mm :update<Bar>make<CR>
map <buffer> <Leader>ma :update<Bar>make all<CR>
map <buffer> <Leader>M :update<CR>:make <Up>
map <buffer> <Leader>mc :make clean<CR>
" Execute file
autocmd Filetype javascript,perl,php,python,ruby,sh
\ map <buffer> <Leader>x :update<Bar>!"%:h/%:t"<CR>
autocmd Filetype c,cpp
\ map <buffer> <Leader>x :!"%:h/%:t:r"<CR>
autocmd Filetype make
\ map <buffer> <Leader>x :update<Bar>make<CR>
autocmd Filetype ebuild
\ map <buffer> <Leader>x :update<Bar>!emerge "=%:s:^.*/\([^/]\+/\)\([^/]\+\)/\2\(-.\+\)\.ebuild$:\1\2\3:"<CR>
" Execute file with args
autocmd Filetype javascript,perl,php,python,ruby,sh
\ map <buffer> <Leader>X :update<CR>:!"%:h/%:t" <Up>
autocmd Filetype c,cpp
\ map <buffer> <Leader>X :!"%:h/%:t:r" <Up>
autocmd Filetype make
\ map <buffer> <Leader>X :update<CR>:make <Up>
autocmd Filetype ebuild
\ map <buffer> <Leader>X :update<CR>:!ebuild "%" <Up>
" auto quickfix
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
""" quit helpers
command! -bang Q q<bang>
command! -bang Qa qa<bang>
command! -bang QA qa<bang>
""" quit for buffers {{{2
function! QuitBuf(...) " {{{3
" function to inteligently close windows and buffers
if a:0 | let bang = a:1
else | let bang = ''
endif
" first check if it's a help/quickfix/preview window
if &buftype == 'help'
execute 'quit' . bang
return
elseif &buftype == 'quickfix'
if getwininfo(win_getid())[0]['loclist'] == 1
" if it's a loclist we can't close it directly, so first move to
" its linked window, then close it from there
execute 'll' . bang
execute 'lclose'
lclose
" and now jump back to the previous position
execute "normal! \<c-o>"
else
execute 'quit' . bang
endif
return
elseif &previewwindow == 1
execute 'pclose' . bang
return
elseif &filetype =~ 'man\|info'
execute 'quit' . bang
return
"elseif exists('b:fugitive_type') || exists('b:fugitive_commit_arguments')
" also check if its from fugitive (e.g. Gdiff window)
"execute 'quit' . bang
"return
endif
" current vars
let c_b = bufnr('%') " current buffer
let c_w = winnr() " current window
let c_t = tabpagenr() " current tabpage
" control vars
let o_b = 1 " assume only buffer
let o_w = 1 " assume only window to buffer
" find if we're the only listed buffer
for b_i in range(1, bufnr('$')) " iterate from first buffer to last
if buflisted(b_i) " valid buffer?
if b_i != c_b
let o_b = 0 | break " not only buffer
endif
endif
endfor
" find if we're the only window linked to the buffer
for t_i in range(1, tabpagenr('$')) " iterate by tab and window
let t_bs = tabpagebuflist(t_i)
for w_i in range(1, tabpagewinnr(t_i, '$'))
if (! (t_i == c_t && w_i == c_w)) && (t_bs[w_i - 1] == c_b)
let o_w = 0 | break " not only window to buffer
endif
endfor
if ! o_w | break | endif
endfor
" TODO - this doesn't seem to work properly when a quickfix is open
" perform the correct operation
let bd_com = 'bdelete' . bang
let bn_com = 'bnext'
let q_com = 'quit' . bang
if o_b && o_w | let x_com = q_com " 1 buf, 1 win : close vim
elseif o_w | let x_com = bd_com " 1/n bufs, 1 win->buf : close buf
elseif o_b | let x_com = q_com " 1 buf, 1/n wins->buf : close win
else | let x_com = bn_com " 1/n bufs, 1/n wins->buf : close ?
endif
execute x_com
endfunction " }}}3
command! Bwq write<Bar>call QuitBuf()
command! Bx update<Bar>call QuitBuf()
command! -bang Bq call QuitBuf('<bang>')
" Close current buffer
nnoremap <silent> ZX :Bx<CR>
nnoremap <silent> ZQ :Bq<CR>
nnoremap <silent> Z!Q :Bq!<CR>
" Close all buffers
nnoremap <silent> ZA :xall<CR>
" Close other buffer and window
nnoremap <silent> Zw :wincmd w<Bar>Bx<CR>
nnoremap <silent> ZW :wincmd w<Bar>Bx<CR>
nnoremap <silent> Zh :wincmd h<Bar>Bx<CR>
nnoremap <silent> ZH :wincmd h<Bar>Bx<CR>
nnoremap <silent> Zj :wincmd j<Bar>Bx<CR>
nnoremap <silent> ZJ :wincmd j<Bar>Bx<CR>
nnoremap <silent> Zk :wincmd k<Bar>Bx<CR>
nnoremap <silent> ZK :wincmd k<Bar>Bx<CR>
nnoremap <silent> Zl :wincmd l<Bar>Bx<CR>
nnoremap <silent> ZL :wincmd l<Bar>Bx<CR>
"""""""""""""""""""""""""""""" {{{1
" Style and Syntax {{{1
""""""""""""""""""""""""" {{{2
if ! $VIM_SIMPLE
filetype plugin indent on " enable file type check and indent
syntax on " enable syntax highlighting
endif
" allow syntax refreshing
noremap <Leader>rs :syntax sync fromstart<CR>
" allow for ineficient regexes
set maxmempattern=100000
""" Tabs {{{2
set tabstop=8 " literal tab width
"autocmd Filetype c,cpp setlocal tabstop=4
set softtabstop=8 " spaces per tab (pressed)
autocmd Filetype json,markdown,rst,xml,xsd,yaml setlocal
\ softtabstop=4
set shiftwidth=4 " spaces per indent
autocmd Filetype ant,dtd,json,proto,rst,terraform,xml,xsd,yaml setlocal
\ shiftwidth=2
set noexpandtab " don't expand tabs to spaces
autocmd Filetype apiblueprint,ant,c,cpp,cql,dtd,java,javascript,jsp,json,markdown,python,terraform,rst,xml,xsd,yaml setlocal
\ expandtab " for MLs, xfce and python 3 compatibility
set smarttab " use shiftwidth for indent, else softtabstop
""" Wrapping {{{2
set linebreak " wraps without <eol>
set breakindent " indent wrappped lines
if &encoding == 'utf-8' | let &showbreak='↪' | else | let &showbreak='>' | endif
set breakindentopt+=sbr " at begining, not start of text
set cpoptions+=n " in the number column
" don't insert comment leader on <CR> or o/O
set formatoptions-=r formatoptions-=o
" code style: wrap at length, normal navigation
autocmd Filetype ant,c,cpp,css,dtd,html,javascript,make,python,sh,vim,xml,xsd setlocal
\ textwidth=79 formatoptions+=a2
\ formatoptions-=l formatoptions-=a formatoptions-=w
" auto wrap at standard terminal width (80) to 2nd line indent,
" allow auto formating long lines
" text style: no line wrap, g{j,k} <==> {j,k} for movement
autocmd Filetype markdown,rst,tex,text setlocal
\ textwidth=0
\ formatoptions+=n
\ autoindent
" overide system vimrc (for text, others standard)
" recognise numbered and bulleted lists
function! s:TextMovement(...)
if a:0 > 0 && a:1 == '!'
nunmap gj
nunmap gk
nunmap j
nunmap k
else
noremap gj j
noremap gk k
noremap j gj
noremap k gk
endif
endfunction
command! -bang TextMovement call s:TextMovement('<bang>')
autocmd Filetype markdown,rst,tex,text TextMovement
" image formats: for use with afterimage
autocmd Filetype bmp,gif,png,xpm,xbm setlocal nowrap
""" file types {{{2
let g:java_highlight_functions = "style"
let g:java_highlight_debug = 1
let g:php_sql_query = 1
let g:php_htmlInStrings = 1
let g:python_highlight_all = 1
let g:python_mode = 'python3'
let g:readline_has_bash = 1
let g:highlight_sedtabs = 1
let g:sh_noisk = 1 " don't add '.' to 'iskeyword'
let g:sh_syn_embed = "asprP"
"let g:vimsyn_embed = "lPr" " default is enabled interpreters
autocmd FileType json hi link jsonCommentError Comment
"""""""""""""""""""""""""""""" {{{1
" File Formats {{{1
""""""""""""""""""""""""" {{{2
"set fileformats=unix " always use Unix file format
"autocmd FileType python set bomb " enable BOM for listend filetypes
" breaks *n?x shebangs (#!/path/2/prog)
let g:tex_flavor = 'latex' " use latex styles
" some JSP projects use .tag for shared snippets
autocmd BufRead,BufNewFile */WEB_INF/tags/*.tag set filetype=jsp
" terraform tfstate files are pure JSON
autocmd BufRead,BufNewFile *.tfstate,*.tfstate.* set filetype=json
" Cassandra Query Language
autocmd BufRead,BufNewFile *.cql,*.cqlsh set filetype=cql
" Jenkins pipeline scripts
autocmd BufRead,BufNewFile Jenkinsfile set filetype=groovy
" Graphviz (dot) files
autocmd BufRead,BufNewFile *.gv set filetype=dot
""" use skeleton files {{{2
autocmd BufNewFile * silent! 0r ~/Templates/%:e.%:e
"""""""""""""""""""""""""""""" {{{1
" Folding {{{1
""""""""""""""""""""""""" {{{2
set foldminlines=1 foldnestmax=10 foldignore=""
function! SplitFoldText(...)
" Function for use with 'foldtext', displays half the window width as the
" literal text, the other half taken up with (modified) v:folddashes and
" the number of lines in the fold.
" Allow calling function with a line number and prepare variables
if a:0
let line = getline(a:1)
let lines = '?'
let dashes = '+' . repeat('-', (level - 1))
else
let line = getline(v:foldstart)
let lines = 1 + v:foldend - v:foldstart
let dashes = '+' . v:folddashes[1:]
endif
" replace tabs with correct number of spaces
"let line = substitute(line, '\t', repeat(' ', &tabstop), 'g')
let split_line = split(line, ' ', 1)
let [line; split_line] = split_line
for item in split_line
let line .= repeat(' ', (&tabstop - (strlen(line) % &tabstop))) . item
endfor
" remove foldmarkers (and trailing text)
let idx = stridx(&foldmarker, ',')
let fmr_s = &foldmarker[:(idx - 1)]
let fmr_e = &foldmarker[(idx + 1):]
let idx = stridx(line, fmr_e)
if idx != -1 | let line = line[:(idx - 1)] | endif
let idx = stridx(line, fmr_s)
if idx != -1 | let line = line[:(idx - 1)] | endif
" make line the right size
let width = winwidth(0) / 2
let length = strlen(line)
if length > (width - 1)
let char = matchlist(&listchars, '.*extends:\(.\),')[1]
if ! strlen(char) | let char = '>' | endif
let line = line[:width - 2] . char
else
let line = line . repeat(' ', width - length)
endif
return line . ' ' . dashes . ' (' . lines . ' lines) '
endfunction
set foldtext=SplitFoldText()
" Don't screw up folds when inserting text that might affect them, until
" leaving insert mode. Foldmethod is local to the window. Protect against
" screwing up folding when switching between windows.
autocmd InsertEnter *
\ if !exists('w:last_fdm')
\| let w:last_fdm = &foldmethod
\| setlocal foldmethod=manual
\|endif
autocmd InsertLeave,WinLeave *
\ if exists('w:last_fdm')
\| let &l:foldmethod = w:last_fdm
\| unlet w:last_fdm
\|endif
""" syntax folds {{{2
let g:apiblueprint_folding = 1
"let g:clojure_fold = 1
"let g:baan_fold = 1
"let g:baan_fold_block = 1
"let g:baan_fold_sql = 1
"let g:eiffel_fold = 1
"let g:fortran_fold = 1
"let g:fortran_fold_conditionals = 1
"let g:fortran_fold_multilinecomments = 1
let g:markdown_folding = 1
let g:vim_markdown_override_foldtext = 0
let g:vim_markdown_folding_style_pythonic = 1
"let g:javaScript_fold = 1 " FIXME: BROKEN
let g:perl_fold = 1
let g:perl_fold_anonymous_subs = 1
let g:perl_fold_blocks = 1
let g:php_folding = 2
let g:r_syntax_folding = 1
let g:rcs_folding = 1
let g:ruby_fold = 1
let g:sh_fold_enabled = 31
let g:tex_fold_enabled = 1
let g:vimsyn_folding = "aflmprPt"
let g:xml_syntax_folding = 1
""" filetype settings {{{2
" let $code =
" "ant,c,cpp,css,dtd,gentoo-init-d,groovy,html,java,javascript,jsp,json,perl,php,prolog,python,ruby,sh,verilog,vhdl,xml,xsd"
autocmd Filetype ant,c,cpp,gentoo-init-d,groovy,html,java,jsp,json,perl,php,ruby,sh,typescript,xml,xsd setlocal
\ foldcolumn=5
\ foldmethod=syntax
\ foldlevel=1
autocmd Filetype apiblueprint,bib,css,markdown,tex setlocal
\ foldcolumn=3
\ foldmethod=syntax
\ foldlevel=1
autocmd Filetype ada,dtd,javascript,prolog,proto,python,verilog,vhdl,yaml setlocal
\ foldcolumn=5
\ foldmethod=indent
\ foldlevel=1
autocmd Filetype c,cpp setlocal foldignore="#"
autocmd Filetype java syn clear javaBraces
autocmd Filetype java syn region javaFoldBraces matchgroup=javaBraces start="{" end="}" transparent fold keepend extend
autocmd Filetype java syn region javaFoldJavadoc start="/\*" end="\*/" transparent fold keepend
"autocmd Filetype python autocmd BufWritePre python mkview
"autocmd Filetype python autocmd BufReadPost python silent loadview
""" folding vim {{{2
function! FoldVim(l)
let line = getline(a:l)
let p_line = getline(a:l - 1)
if line =~# '^\"\{30\}' || line =~ '\svim\?:\s'
return 0
elseif p_line =~# '^\"\{30\}'
return '>1'
elseif line =~# '^\"\{25\}'
return 1
elseif line =~# '^\"\{3\} '
return '>2'
"elseif p_line =~# '^\"\{3\}'
"return 2
else
if line !~# '^\s*end'
return 2 + float2nr(indent(a:l) / &shiftwidth)
else
return 3 + float2nr(indent(a:l) / &shiftwidth)
endif
"let i_diff = float2nr((indent(a:l) - indent(a:l - 1)) / &shiftwidth)
"if line =~ '^end' | let i_diff += 1 | endif
"if p_line =~ '^end' | let i_diff -= 1 | endif
"if i_diff > 0
"return 'a' . abs(i_diff)
"elseif i_diff < 0
"return 's' . abs(i_diff)
"else
"return '='
"endif
endif
endfunction
autocmd Filetype vim setlocal
\ foldcolumn=4
\ foldmethod=marker
\ foldexpr=FoldVim(v:lnum)
\ foldlevel=1
"autocmd BufRead **vimrc setlocal foldmethod=expr foldexpr=Fold_vimrc(v:lnum)
"autocmd Filetype vim setlocal foldlevel=1
""" folding tar {{{2
function! FoldTar(l)
let line = getline(a:l)
if strlen(line) < 1 | return 0 | endif
if line[0] == '"' | return 1 | endif
return count(split(line, '\zs'), '/') + 1
endfunction
autocmd Filetype tar setlocal
\ foldcolumn=0
\ foldmethod=expr
\ foldexpr=FoldTar(v:lnum)
\ foldlevel=2
"""""""""""""""""""""""""""""" {{{1
" Navigation {{{1
""""""""""""""""""""""""" {{{2
""" Quick move windows {{{2
nnoremap gw <C-W>
nnoremap gW <C-W>
""" Quick move buffers {{{2
nnoremap <silent> gb :bnext<CR>
nnoremap <silent> gB :bprevious<CR>
""" Redifine jump mappings {{{2
noremap <Leader>i <C-i>
noremap <Leader>o <C-o>
" By default use tags {{{3
nnoremap g] <C-]>
nnoremap g} g<C-]>
nnoremap g<C-]> g]
nnoremap g[ <C-T>
" typescript {{{3
" Note: we also support javascript for looking at compiled code
command! -bang TsuJumpMappings
\ if "<bang>" == "!" ||
\ (exists('*tsuquyomi#statusServer') && tsuquyomi#statusServer() == 'run')
\| if !(exists('b:tsu_done_mappings') && b:tsu_done_mappings)
\| nnoremap <buffer> g] :TsuDefinition<CR>
\| nnoremap <buffer> g} :TsuTypeDefinition<CR>
\| nnoremap <buffer> g[ :TsuGoBack<CR>
\| nnoremap <buffer> g{ :TsuReferences<CR>
\| let b:tsu_done_mappings=1
\| endif
\|endif
autocmd Filetype typescript TsuJumpMappings!
autocmd Filetype javascript TsuJumpMappings
""" Redifine goto mark mappings {{{2
" Think the default should be the position in the previous line, rather than
" the start of it. Alse have ` set as tmux prefix, so using <Leader>' as start
" of previous line (although send-prefix allows ` to work, wil become confusing
" in nested sessions).
noremap <Leader>' '
noremap ' `
""" maps for location/quickfix next/prev {{{2
noremap gll :ll<CR>
noremap gln :lnext<CR>
noremap glN :lNext<CR>
noremap glp :lprevious<CR>
noremap gcc :cc<CR>
noremap gcn :cnext<CR>
noremap gcN :cNext<CR>
noremap gcp :cprevious<CR>
"""""""""""""""""""""""""""""" {{{1
" Diff {{{1
""""""""""""""""""""""""" {{{2
command! DiffToggle
\ if &diff | diffoff | else | diffthis | endif
noremap <Leader>dt :DiffToggle<CR>
noremap <Leader>rd :diffupdate<CR>
noremap <Leader>du :diffupdate<CR>
""" diffget/diffput/do/dp with winnr {{{3
" TODO dp/do with winbufnr()
"command! -nargs=? -range -bar DiffGet
" \ <range>diffget <args>
"""""""""""""""""""""""""""""" {{{1
" Spelling {{{1
""""""""""""""""""""""""" {{{2
" set spell " enable spell check
nnoremap <Leader><Leader>sp :let &spell = ! &spell<CR>
autocmd Filetype css,html,javascript,php,tex,text setlocal spell
autocmd Filetype conf,help,info,man setlocal nospell
"autocmd StdinReadPost * setlocal nospell " but not in man
set spelllang=en_gb " spell check language to GB
" set spellfile as 1: my generic file; 2: local (e.g. job); 3?: filetype
let &spellfile = $HOME."/.vim/spell/I.".&encoding.".add"
\ .",".$HOME."/.vim/spell/local.".&encoding.".add"
autocmd FileType * let &l:spellfile .= ",".$HOME."/.vim/spell/".&l:filetype.".".&l:encoding.".add"
" set dictionary+=/usr/share/dict/words " add standard words
"""""""""""""""""""""""""""""" {{{1
" Completion {{{1
""""""""""""""""""""""""" {{{2
"set wildmenu
set wildmode=longest:list " shell style file completion
set completeopt=longest,menuone,menu,preview
set complete=.,k,w,b,u,t,i " add dictionary completion
"set autoindent " indent new line to same as previous
"set smartindent " indent on code type
" automatically open and close the popup menu / preview window
autocmd InsertLeave * if pumvisible() == 0|silent! pclose|endif
"set omnifunc=syntaxcomplete#Complete
"autocmd FileType c set omnifunc=ccomplete#Complete
"autocmd FileType css set omnifunc=csscomplete#CompleteCSS
"autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
"autocmd FileType java set omnifunc=javacomplete#Complete
"autocmd FileType jsp set omnifunc=javacomplete#Complete
"autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
"autocmd FileType python set omnifunc=pythoncomplete#Complete
"autocmd FileType ruby set omnifunc=pythoncomplete#Complete
"autocmd FileType sql set omnifunc=sqlcomplete#Complete
""" continue completion {{{2
"imap <silent> <expr> <buffer> <CR> pumvisible() ? "<CR><C-R>=(col('.')-1&&match(getline(line('.')), '\\.', col('.')-2) == col('.')-2)?\"\<lt>C-X>\<lt>C-O>\":\"\"<CR>" : "<CR>"
"""""""""""""""""""""""""""""" {{{1
" Plugin configuration {{{1
""""""""""""""""""""""""" {{{2
""" csv {{{2
autocmd BufRead,BufNewFile *.?sv setfiletype csv " Allow for ?sv file editing
autocmd BufNewFile *.csv let g:csv_delim = ',' " set the csv delimiter for new files
autocmd BufNewFile *.tsv let g:csv_delim = ' ' " tsv delimiter ''
let g:csv_autocmd_arrange = 1 " auto arrange columns
function! CSVAlignColumns(align, bang) range
exec "silent ".a:firstline.",".a:lastline."UnArrangeColumn"
let b:csv_arrange_leftalign = a:align ==? "l" || a:align ==? "left" ? 1 : 0
exec "silent ".a:firstline.",".a:lastline."ArrangeColumn".a:bang
endfunction
autocmd FileType csv command! -range=% -bang -nargs=1 CSVAlignColumns
\ <line1>,<line2>call CSVAlignColumns(<args>, "<bang>")
autocmd FileType csv noremap <Leader>cal :CSVAlignColumns "left"<CR>
autocmd FileType csv noremap <Leader>car :CSVAlignColumns "right"<CR>
"TODO: following for visual and no header
autocmd FileType csv nnoremap <Leader>cs :2,$CSVSort<CR>
autocmd FileType csv nnoremap <Leader>cS :2,$CSVSort!<CR>
""" ctags {{{2
"autocmd BufWritePost c,cpp,*.h !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
"noremap mtl :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>