forked from adragomir/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
1763 lines (1524 loc) · 45.4 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
" set PATH correctly {{{
if has("macunix") && has("gui_running") && system('ps xw | grep -c "[V]im -psn"') > 0
" Get the value of $PATH from a login shell.
if $SHELL =~ '/\(sh\|csh\|bash\|tcsh\|zsh\)$'
let s:path = system("echo echo VIMPATH'${PATH}' | $SHELL -l")
let $PATH = matchstr(s:path, 'VIMPATH\zs.\{-}\ze\n')
endif
endif
"}}}
" Settings {{{
set runtimepath+=$HOME/.vim/andrei
" general settings
set nocompatible " use VI incompatible features
let no_buffers_menu=1
set noautochdir
set history=10000 " number of history items
set shiftround
"set autowriteall
" backup settings
set nobackup " do not keep backups after close
set nowritebackup " do not keep a backup while working
set noswapfile " don't keep swp files either
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,/private/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
" ui settings
set ruler " show the cursor position all the time
set scrolloff=3 " start scrolling before end
set showcmd " show incomplete commands
set number " show line numbers
set whichwrap=<,>,h,l,b,s,~,[,]
set shortmess=aTI " supress some file messages
set sidescrolloff=4 " minchars to show around cursor
if has("gui_running")
set mouse=a
endif
set selectmode=mouse,key " select model
set keymodel=startsel ",stopsel
set autoread " read outside modified files
set encoding=UTF-8 " file encoding
set modelines=0
set formatoptions=tcroqn1 " auto format
set colorcolumn=+1
"set guioptions=cr+bie"M"m " aA BAD
set guioptions=ci+Mgrbe " NEVER EVER put ''a in here
"set guioptions=+
" visual cues
set ignorecase " ignore case when searching
set smartcase " ignore case when searching
set hlsearch " highlight last search
set incsearch " show matches while searching
set gdefault
set laststatus=2 " always show status line
"set cursorline
set showbreak=↪ " character to show that a line is wrapped
set fillchars=diff:⣿
set showcmd " show number of selected chars/lines in status
set showmatch " briefly jump to matching brace
set matchtime=1 " show matching brace time (1/10 seconds)
set showmode " show mode in status when not in normal mode
set nostartofline " don't move to start of line after commands
set statusline=%-2(%M\ %)%5l,%-5v%<%F\ %m%=[tab:%{&ts},%{&sts},%{&sw},%{&et?'et':'noet'}]\ [byte:\ %3b]\ [offset:\ %5o]\ %(%-5([%R%H%W]\ %)\ %10([%Y]%{ShowFileFormatFlag(&fileformat)}\ %)\ %L\ lines%)
set undolevels=10000
set pumheight=10
set viminfo=%,h,'1000,"1000,:1000,n~/.vim/tmp/.viminfo
set scrolljump=10
set virtualedit+=block
set novisualbell
set noerrorbells
set t_vb=
set winaltkeys=no
set writeany
set iskeyword=@,48-57,128-167,224-235,_
set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮,trail:.
set showtabline=2
set matchtime=0
set complete=.,w,b,u,t,i " completion by Ctrl-N
set completeopt=menu,menuone,longest
set ttyfast
"set notimeout
"set ttimeout
set timeoutlen=500
set ttimeoutlen=200
set guipty
set clipboard= "unnamed ",unnamedplus,autoselect
set undofile
set undoreload=10000
set undodir=~/.vim/tmp/undo/
set backupdir=~/.vim/tmp/backup " store backups under ~/.vim/backup
set backup
set directory=~/.vim/tmp/swap " keep swp files under ~/.vim/swap
" settings: windows and buffers
"set noequalalways
set guiheadroom=0
" When off a buffer is unloaded when it is |abandon|ed.
set hidden
set splitbelow " split windows below current one
set title
set linebreak
set dictionary=/usr/share/dict/words
set exrc
set gcr=a:blinkon0
set switchbuf=usetab
" settings: line endings
"set ff=unix
"set ffs=unix
" settings: grep
set grepprg=$HOME/bin/ack\ --noenv
set grepformat=%f:%l:%m
" settings: tabs and indentin
set autoindent
set nocindent
set nosmartindent
set copyindent
"set smarttab
"set indentexpr=
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set cmdheight=2
set laststatus=2
set suffixes+=.lo,.o,.moc,.la,.closure,.loT
set suffixes+=.bak,~,.o,.h,.info,.swp,.obj
set suffixes+=class,.6
"}}}
" wildmenu settings {{{
set wildmenu
set wildmode=list:longest,full
set wildignore+=.svn,CVS,.git,.hg
set wildignore+=*.aux,*.out,*.toc " latex files
set wildignore+=*.o,*.d,*.obj,*.dylib,*.so,*.exe,*.manifest,*.a,*.mo,*.la " objects
set wildignore+=*.class,*.jar
set wildignore+=*.jpg,*.jpeg,*.png,*.gif,*.tiff,*.xmp
set wildignore+=*.sw?,*.bak
set wildignore+=*.6,*.out
set wildignore+=.DS_Store
set wildignore+=*.pyc,*.class,*.luac
" }}}
" pathogen {{{
call pathogen#helptags()
call pathogen#infect()
" }}}
" mapleader {{{
let mapleader = ","
let maplocalleader = ","
" }}}
" look & feel {{{
set t_Co=256
set background=dark
set t_Co=16
let g:solarized_termtrans=1
let g:solarized_termcolors=256
let g:solarized_italic=0
colorscheme solarized
if has("gui_running") && has("macunix")
set guifont=Inconsolata\ For\ Powerline:h15
set antialias
endif
" }}}
" gui settings {{{
if has("gui_running") && has("macunix")
" behave mswin
set fuoptions=maxvert,maxhorz
set selectmode=mouse "key,mouse
set mousemodel=popup
set keymodel=startsel ",stopsel
set selection=exclusive
" source $VIMRUNTIME/mswin.vim
" mswin.vim, INLINE
" backspace and cursor keys wrap to previous/next line
set backspace=indent,eol,start whichwrap+=<,>,[,]
" backspace in Visual mode deletes selection
vnoremap <BS> d
" CTRL-X and SHIFT-Del are Cut
vnoremap <D-X> "+x
vnoremap <S-Del> "+x
" CTRL-C and CTRL-Insert are Copy
vnoremap <special> <D-C> "+y
vnoremap <C-Insert> "+y
" CTRL-V and SHIFT-Insert are Paste
map <D-V> "+gP
map <S-Insert> "+gP
cmap <D-V> <C-R>+
cmap <S-Insert> <C-R>+
" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature. They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.
exe 'inoremap <script> <D-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <D-V>' paste#paste_cmd['v']
imap <S-Insert> <D-V>
vmap <S-Insert> <D-V>
" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q> <C-V>
" For CTRL-V to work autoselect must be off.
" On Unix we have two selections, autoselect can be used.
if !has("unix")
set guioptions-=a
endif
" CTRL-A is Select all
noremap <D-A> gggH<C-O>G
inoremap <D-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <D-A> <C-C>gggH<C-O>G
onoremap <D-A> <C-C>gggH<C-O>G
snoremap <D-A> <C-C>gggH<C-O>G
xnoremap <D-A> <C-C>ggVG
" end mswin.vim
"source $VIMRUNTIME/macmap.vim.old
" macmap.vim.old INLINE
vnoremap <special> <D-x> "+x
vnoremap <special> <D-c> "+y
cnoremap <special> <D-c> <C-Y>
nnoremap <special> <D-v> "+gP
cnoremap <special> <D-v> <C-R>+
execute 'vnoremap <script> <special> <D-v>' paste#paste_cmd['v']
execute 'inoremap <script> <special> <D-v>' paste#paste_cmd['i']
nnoremap <silent> <special> <D-a> :if &slm != ""<Bar>exe ":norm gggH<C-O>G"<Bar> else<Bar>exe ":norm ggVG"<Bar>endif<CR>
vmap <special> <D-a> <Esc><D-a>
imap <special> <D-a> <Esc><D-a>
cmap <special> <D-a> <C-C><D-a>
omap <special> <D-a> <Esc><D-a>
" end macmap.vim
elseif has("gui_running")
" behave mswin
set selectmode=mouse "key,mouse
set mousemodel=popup
set keymodel=startsel ",stopsel
set selection=exclusive
" source $VIMRUNTIME/mswin.vim
" mswin.vim, INLINE
" backspace and cursor keys wrap to previous/next line
set backspace=indent,eol,start whichwrap+=<,>,[,]
" backspace in Visual mode deletes selection
vnoremap <BS> d
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x
" CTRL-C and CTRL-Insert are Copy
vnoremap <special> <C-C> "+y
vnoremap <C-Insert> "+y
" CTRL-V and SHIFT-Insert are Paste
map <C-V> "+gP
map <S-Insert> "+gP
cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+
" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature. They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
imap <S-Insert> <C-V>
vmap <S-Insert> <C-V>
" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q> <C-V>
" For CTRL-V to work autoselect must be off.
" On Unix we have two selections, autoselect can be used.
if !has("unix")
set guioptions-=a
endif
" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
" end mswin.vim
"source $VIMRUNTIME/macmap.vim.old
" macmap.vim.old INLINE
vnoremap <special> <C-x> "+x
vnoremap <special> <C-c> "+y
cnoremap <special> <C-c> <C-Y>
nnoremap <special> <C-v> "+gP
cnoremap <special> <C-v> <C-R>+
execute 'vnoremap <script> <special> <C-v>' paste#paste_cmd['v']
execute 'inoremap <script> <special> <C-v>' paste#paste_cmd['i']
nnoremap <silent> <special> <C-a> :if &slm != ""<Bar>exe ":norm gggH<C-O>G"<Bar> else<Bar>exe ":norm ggVG"<Bar>endif<CR>
vmap <special> <C-a> <Esc><C-a>
imap <special> <C-a> <Esc><C-a>
cmap <special> <C-a> <C-C><C-a>
omap <special> <C-a> <Esc><C-a>
" end macmap.vim
endif
" }}}
" syntax highlighting {{{
syntax enable
syntax on
filetype on
filetype indent on
filetype plugin on
hi SignColor guibg=red
autocmd BufEnter * :syntax sync fromstart
" }}}
" my functions {{{
function! EatChar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunction
function! MakeSpacelessIabbrev(from, to)
execute "iabbrev <silent> ".a:from." ".a:to."<C-R>=EatChar('\\s')<CR>"
endfunction
function! WordFrequency() range
let all = split(join(getline(a:firstline, a:lastline)), '\A\+')
let frequencies = {}
for word in all
let frequencies[word] = get(frequencies, word, 0) + 1
endfor
new
setlocal buftype=nofile bufhidden=hide noswapfile tabstop=20
for [key,value] in items(frequencies)
call append('$', key."\t".value)
endfor
sort i
endfunction
command! -range=% WordFrequency <line1>,<line2>call WordFrequency()
function! OnTabLeave()
if UselessBuffer('%')
bwipeout
endif
endfunction
function! UselessBuffer(...)
let l:bufname = a:0 == 1 ? a:1 : '%'
if (getbufvar(l:bufname, '&mod') == 0 && index(['', '[No Name]', '[No File]'], bufname(l:bufname)) >= 0)
return 1
end
return 0
endfunction
function! Tabnew()
if (!UselessBuffer('%'))
tabnew
endif
endfunction
" tab settings
function! IndentingGeneralSettings()
set autoindent nocindent nosmartindent
set indentexpr=
endfunction
function! IndentingSetTabsize(size)
let &tabstop = a:size
let &shiftwidth = a:size
let &softtabstop = a:size
endfunction
function! IndentingSetSpaces(size)
set expandtab
call IndentingGeneralSettings()
call IndentingSetTabsize(a:size)
endfunction
function! IndentingSetTabs()
set noexpandtab
call IndentingGeneralSettings()
call IndentingSetTabsize(4)
endfunction
function! SwapUp()
if ( line( '.' ) > 1 )
let cur_col = virtcol(".")
if ( line( '.' ) == line( '$' ) )
normal ddP
else
normal ddkP
endif
execute "normal " . cur_col . "|"
endif
endfunction
function! SwapDown()
if ( line( '.' ) < line( '$' ) )
let cur_col = virtcol(".")
normal ddp
execute "normal " . cur_col . "|"
endif
endfunction
function! MoveCursor(move, mode)
if (a:move == 'h')
if (a:mode == '0')
normal 0
elseif (a:mode =~ '^\^')
if (a:mode == '^g')
normal g^
elseif (a:mode == '^n')
normal ^
endif
endif
elseif (a:move == 'e')
if (a:mode =~ '^\$')
if (a:mode == '$g')
normal g$
elseif (a:mode == '$n')
normal $
endif
endif
endif
endfunction
function! HomeKey()
let oldmode = mode()
let oldcol = col('.')
call MoveCursor('h', '^n')
let newcol = col('.')
if (oldcol == newcol)
if (&wrap != 1) || (newcol <= winwidth(0) - 20)
call MoveCursor('h', '0')
let lastcol = col('.')
if (newcol == lastcol)
if (newcol == oldcol)
normal i
else
call MoveCursor('h', '^n')
endif
else
call MoveCursor('h', '0')
endif
endif
endif
endfunction
function! EndKey()
call MoveCursor('e', '$g')
endfunction
function! StrMatchNo(haystack, needle)
let LastMatch = match(a:haystack, a:needle)
if LastMatch > -1
let Result = 1
while LastMatch > -1
let LastMatch = match(a:haystack, a:needle, LastMatch+1)
if LastMatch > -1
let Result = Result + 1
endif
endwhile
else
let Result = 0
endif
return Result
endfunction
function! ConditionalExecute(action)
if a:action == "write"
if &modified == 1
silent write
endif
elseif a:action == "quit"
new
execute "normal! \<C-w>\<C-w>"
silent quit
endif
endfunction
function! InsertBrace()
if strpart(getline("."), col(".")-1, 1) != " "
let s:seq = " "
else
let s:seq = ""
endif
let s:seq = s:seq . "{\<CR>}\<Left>\<CR>\<Up>\<Tab>"
execute "normal a" . s:seq
endfunction
" calls KeyMapExec for all combinations of modes and modifiers
function! KeyMap(modes, special, modifiers, key, action)
if a:modes == ""
if a:modifiers == ""
call KeyMapExec(a:modes, a:special, a:modifiers, a:key, a:action)
else
for j in range(len(a:modifiers))
call KeyMapExec(a:modes, a:special, a:modifiers[j], a:key, a:action)
endfor
endif
else
for i in range(len(a:modes))
if a:modifiers == ""
call KeyMapExec(a:modes[i], a:special, a:modifiers, a:key, a:action)
else
for j in range(len(a:modifiers))
call KeyMapExec(a:modes[i], a:special, a:modifiers[j], a:key, a:action)
endfor
endif
endfor
endif
endfunction
" mode: n,i,v
" modifier: C,D,L,M,S
" key: a,<F2>,<Left>, etc
" action: \o/
function! KeyMapExec(mode, special, modifier, key, action)
if a:modifier=="D" && !has("macunix")
return
end
" arg
let s:arg = substitute(" <silent> ", "<>", "", "")
" if no <CR>s or only one <CR> at end, use <C-o> to better preserve cursor position
" examples:
" gt
" :bd<CR>
" otherwise, use <Esc> and a
" examples:
" :s/a/b/<CR>:s/c/d/<CR>
" :s/e/f/<CR>dd
let crs = len(split(a:action, "<CR>"))
if crs == 0 || (crs == 1 && a:action =~ '<CR>$')
let s:pre = "<C-o>"
let s:post = ""
else
let s:pre = "<Esc>"
let s:post = "a"
endif
" put what to map in s:key
let s:key = substitute(a:key, '[<>]', '', 'g')
if a:modifier == ""
let s:key = a:key
elseif a:modifier == "L"
let s:key = "<Leader>" . a:key
else " C,D,M,S
let s:key = "<" . a:modifier . "-" . s:key . ">"
end
" put map in s:map
let s:map = a:mode . "noremap" . a:special . s:key . " "
if a:mode == "i"
let s:map .= s:pre . a:action . s:post
else
let s:map .= a:action
endif
" \o/\O/\o/
"echo s:map
execute s:map
endfunction
function! OpenFileUnderCursor()
let FileName = expand("<cfile>")
if (!filereadable(FileName))
if (filereadable("./" . FileName))
let FileName = "./" . FileName
else
let cpwd = substitute(getcwd(), '\([^/]\)$', '\1/', '')
let fpwd = substitute(FileName, '^.\{-}\(/.*/\).*$', '\1', '')
if (match(cpwd, fpwd . '$'))
let FileName = substitute(FileName, '^.*/\(.*\)$', '\1', '')
endif
endif
endif
let OldPath = getcwd()
silent cd %:p:h
if (filereadable(FileName))
execute "silent sp +e " . FileName
else
echohl error
echo "File '" . FileName . "' not found."
echohl normal
endif
execute "silent cd " . OldPath
endfunction
function! GetSynUnder()
return synIDattr(synID(line('.'), col('.'), 1), 'name')
endfunction
function! GetCharUnder()
return strpart(getline('.'), col('.') - 1, 1)
endfunction
function! GetCharBefore(offset)
return strpart(getline('.'), col('.') - (a:offset + 1), 1)
endfunction
function! GetCharAfter()
return strpart(getline('.'), col('.'), 1)
endfunction
function! AtEnd()
return col('$') == col('.')
endfunction
function! GetStringBeforeCursor(offset)
return strpart(getline('.'), 0, col('.') - a:offset)
endfunction
function! GetStringAfterCursor()
return strpart(getline("."), col("."))
endfunction
function! GetWordBeforeCursor(keep_spaces)
let regexp = '^.*\(\<\w\+\)'
if !a:keep_spaces
let regexp .= '\s*'
endif
let regexp .= '$'
return substitute(GetStringBeforeCursor(0), regexp, '\1', '')
endfunction
function! GetExactWordBeforeCursor(offset)
let x = matchlist(GetStringBeforeCursor(a:offset), '\(\w\w*\)\s*$')
if len(x) > 0
return x[1]
else
return GetStringBeforeCursor(a:offset)
end
"return substitute(GetStringBeforeCursor(a:offset), '^.*\(\w\w*\)\s*$', '\1', '')
endfunction
function! GetFirstWord()
return substitute(getline('.'), '^\W*\(\<\w\+\).*$', '\1', '')
endfunction
function! GetStringBeforeWord()
return substitute(GetStringBeforeCursor(), '^.*\(\W\{-1,}\)\<\w\{-1,}\W*$', '\1', '')
endfunction
function! GetWordBeforeParen()
return substitute(GetStringBeforeCursor(), '^.\{-}\(\<\w\{-1,}\)\s*(.*$', '\1', '')
endfunction
function! UpcaseWordBeforeCursor()
let Line = substitute(GetStringBeforeCursor(), '^\(.*\)\(\<\w\{-1,}\)\(\W*\)$', '\1\U\2\E\3', '')
call setline(".", Line . GetStringAfterCursor())
endfunction
function! GetWordUnder()
let WordBeginning = substitute(GetStringBeforeCursor(), '^.*\<\(\w\{-1,}\)$', '\1', '')
if match(GetStringAfterCursor(), '\w') == 0
let WordEnd = substitute(GetStringAfterCursor(), '^\<\(\w\{-1,}\)\>.*$', '\1', '')
else
let WordEnd = ''
endif
let Word = WordBeginning . WordEnd
return Word
endfunction
function! CountOccurances(haystack, needle)
let occurances = 0
let lastpos = 0
let firstiter = 1
while lastpos > -1
if firstiter
let lastpos = match(a:haystack, a:needle, lastpos)
else
let lastpos = match(a:haystack, a:needle, lastpos + 1)
endif
let firstiter = 0
if lastpos > -1
let occurances = occurances + 1
endif
endwhile
return occurances
endfunction
function! InsideTag()
let str = GetStringBeforeCursor(0) . GetCharUnder()
return str =~ '^.*<[^/>]*$'
endfunction
function! InsideQuote(char)
let str = GetStringBeforeCursor(0) . GetCharUnder()
if !InsideTag()
let tags_complete = CountOccurances(str, '<[^/>]*>')
let tags_incomplete = CountOccurances(str, '<\w')
let tags = tags_incomplete - tags_complete
return (CountOccurances(str, a:char) - tags) % 2 != 0
else
return CountOccurances(str, a:char) % 2 != 0
endif
endfunction
function! ExpandTemplate(ignore_quote)
if a:ignore_quote || GetSynUnder() == 'htmlString' || (!InsideQuote("'") && !InsideQuote('"'))
let cword = GetExactWordBeforeCursor(1)
if exists('g:template' . &ft . cword)
return "\<C-W>" . g:template{&ft}{cword}
elseif exists('g:template_' . cword)
return "\<C-W>" . g:template_{cword}
endif
endif
return ExpandTag(' ')
endfunction
function! ExpandTag(char)
if a:char == '>'
if GetCharUnder() == '>'
return "\<Right>"
elseif GetCharBefore(1) == '>' && (&ft == 'php' || &ft == 'html')
if &ft == 'php' && GetCharBefore(2) == '?'
return '>'
endif
return "\<CR>\<CR>\<Up>\<Tab>"
endif
endif
let sbefore = GetStringBeforeCursor(0)
if GetCharUnder() == '>'
return a:char
endif
if sbefore =~ '^.*<\w\+\S*$' && (&ft == 'php' || &ft == 'html')
let cword = GetExactWordBeforeCursor(1)
let sbefore1 = strpart(sbefore, 0, strlen(sbefore) - 1)
if cword !~ '>' && CountOccurances(sbefore1, '<') > CountOccurances(sbefore1, '>')
let cleft = repeat("\<Left>", len(cword) + 4)
let retval = ''
let close_tag = '></' . cword . '>' . cleft
if cword == 'input' || cword == 'label' || cword == 'br' || cword == 'hr'
let retval .= ">\<Left>"
else
let retval .= close_tag
endif
if a:char == ' '
let retval = ' ' . retval
else
let retval .= "\<Right>"
endif
return retval
endif
return a:char
endif
return a:char
endfunction
" Visual mode functions
function! Enclose(mode, indent)
if a:mode == '{'
let start = '{'
let end = '}'
elseif a:mode == '/'
let start = '/**'
let end = '/**/'
endif
let extra = ''
if a:indent
let extra = "\<BS>"
endif
call cursor(line("'<"), col("'<"))
execute "normal! O" . extra . start
call cursor(line("'>"), col("'>"))
execute "normal! o" . extra . end
endfunction
function! ColonComplete()
normal! a:
endfunction
function! ShowFileFormatFlag(var)
if ( a:var == 'dos' )
return '[DOS]'
elseif ( a:var == 'mac' )
return '[MAC]'
else
return '[UNIX]'
endif
endfunction
function! InsertDateTime()
execute "normal a" . strftime("%A, %Y-%m-%d %H:%M:%S")
endfunction
function! GuiTabLabel()
let label = v:lnum
let bufnrlist = tabpagebuflist(v:lnum)
" Add '+' if one of the buffers in the tab page is modified
for bufnr in bufnrlist
if getbufvar(bufnr, "&modified")
let label .= '+'
break
endif
endfor
" Append the number of windows in the tab page if more than one
let wincount = tabpagewinnr(v:lnum, '$')
if wincount > 1
let label .= wincount
endif
if label != ''
let label .= ' '
endif
let guifname = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])"MyTabLabel(bufnrlist[tabpagewinnr(v:lnum) - 1]) "
let guifname = substitute(guifname, '^\(.*\)/\([^/]*\)$', '\2', '')
" Append the buffer name
return label . guifname
endfunction
function! MyTabLine()
let s = ""
for i in range(tabpagenr('$'))
" select the highlighting
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T'
" the label is made by MyTabLabel()
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let s .= '%#TabLineFill#%T'
" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999Xclose'
endif
return s
endfunction
function! MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let guifname = bufname(buflist[winnr - 1])
let guifname = substitute(guifname, '^\(.*\)/\([^/]*\)$', '\2', '')
return '[' . string(a:n) . ']' . guifname
endfunction
function! OpenAllBuffersInTabs()
ruby << EOF
require 'pp'
numtabs = VIM::evaluate("tabpagenr('$')")
buffers = []
for i in 0..(VIM::Buffer.count - 1)
buffers << VIM::Buffer[i]
end
buffers.each { |b|
}
puts numtabs
EOF
endfunction
function! GuiEnter()
set columns=150 lines=49
" open tabs for all the open buffers
let g:GuiEnter_tablist = []
for i in range(tabpagenr('$'))
call extend(g:GuiEnter_tablist, tabpagebuflist(i + 1))
endfor
ruby << EOF
require 'pp'
numtabs = VIM::evaluate("tabpagenr('$')")
buffers = []
for i in 0..(VIM::Buffer.count - 1)
buffers << VIM::Buffer[i]
end
puts numtabs
EOF
endfunction
" helper function to toggle hex mode
function! ToggleHex()
" hex mode should be considered a read-only operation
" save values for modified and read-only for restoration later,
" and clear the read-only flag for now
let l:modified=&mod
let l:oldreadonly=&readonly
let &readonly=0
let l:oldmodifiable=&modifiable
let &modifiable=1
if !exists("b:editHex") || !b:editHex
" save old options
let b:oldft=&ft
let b:oldbin=&bin
" set new options
setlocal binary " make sure it overrides any textwidth, etc.
let &ft="xxd"
" set status
let b:editHex=1
" switch to hex editor
%!xxd
else
" restore old options
let &ft=b:oldft
if !b:oldbin
setlocal nobinary
endif
" set status
let b:editHex=0
" return to normal editing
%!xxd -r
endif
" restore values for modified and read only state
let &mod=l:modified
let &readonly=l:oldreadonly
let &modifiable=l:oldmodifiable
endfunction
function! ContextSettings()
"set indentexpr=none
let l:NBuffers = bufnr('$')
if l:NBuffers > 1 && bufexists(1) && buflisted(1) && !getbufvar(1, "&bufsecret")
:bw 1
endif
endfunction
function! OpenNewTabOnFileOpen()
let fName = expand('<afile>')
if fName != ""
exe 'tablast | tabe <afile>'
else
exe 'tablast | tabnew'
endif
endfunction
function! ToggleScratch()
if expand('%') == g:ScratchBufferName
quit
else
Sscratch
endif
endfunction
" files & folders functions
function! PathToShortHome(path)
return substitute(a:path, $HOME, "~", "")
endfunction
function! CwdShort()
return substitute(PathToShortHome(getcwd()), "\\", "/", "g")
endfunction
function! FizzyReIndexCwd()
call FizzyReIndex(getcwd())
endfunction
function! FizzyReIndex(dir)
" if (a:dir =~ 'work\/projects\/\w\w*')
echo "reindexing " . a:dir
FizzyFileRenewCache
FizzyDirRenewCache
" endif
endfunction
let g:CWD = ""
function! Cd(cd)
exec 'cd ' . escape(a:cd, " ")
let g:CWD = getcwd()
return getcwd()
endfunction
function! CdReset()
if g:CWD == ""
let g:CWD = getcwd()
else