-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdot.vimrc
2799 lines (2045 loc) · 67.8 KB
/
dot.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
" My .vimrc
" Notes "{{{1
"
" * This file consists of "sections".
"
" - The name of each section should be single word.
"
" * Each section consists of zero or more "subsections".
"
" - There is no rule for the name of each subsection.
"
" * The last subsection in a section should be named as "Misc.".
"
" * Whenever new subsection is inserted,
" it should be inserted just before "Misc." subsection.
"
" * If a setting can be categorized into two or more sections,
" it should be put into the most bottom section in this file.
"
" For example, key mappings for a specific plugin should be put into the
" "Plugins" section.
"
"
" Coding Rule
"
" * Separate sections with 8 blank lines.
"
" * Separate subsections with 4 blank lines.
"
" * Indentation: See the modelines at the bottom of this file.
"
" * Character Encoding: Use UTF-8 for this file and other files such as
" plugins, but this file must contain only unibyte (i.e. 7-bit ASCII)
" characters.
"
" Because changing 'encoding' does not affect the character encoding of
" existing buffers, so that each multibyte character will be treated as
" multiple single byte characters at the first time of loading this file.
" For example, if this file contains a character U+3042 (Japanese Hiragana
" "A"), it will be converted into 3 independent bytes -- E3, 81 and 82.
"
" * Limit all lines to a maximum of 79 characters.
"
" * Separate {lhs} and {rhs} of key mappings with 2 spaces.
"
" * Separate {cmd} and {rep} of :command definitions with 2 spaces.
"
" * Sort arguments for :command such as -nargs=* and others by alphabetically
" order.
"
" * Write the full name for each command -- don't abbreviate it.
" For example, write "nnoremap", not "nn".
"
" * Key Notation:
"
" - Control-keys: Write as <C-x>, neither <C-X> nor <c-x>.
"
" - Carriage return: Write as <Return>, neither <Enter> nor <CR>.
"
" - Other characters: Write as same as :help key-notation
"
" * Line continuation:
"
" - At the middle of key mappings, abbreviations and other proler places:
" Write "\" at the previous column of the start of the {rhs}.
"
" - Others: Write "\" at the same column of the beggining of the command.
"
" - Examples:
"
" execute "echo"
" \ "foo"
" \ "baz"
"
" map <silent> xyzzy :<C-u>if has('cryptv')
" \| X
" \|endif<Return>
"
" * Don't align columns. So don't write like the following code:
"
" map <expr> foo bar
" noremap <silent> bar baz
"
" instead, write like the following code:
"
" map <expr> foo bar
" noremap <silent> bar baz
"
" * Naming:
"
" - Functions: Don't use upper case characters if possible.
"
" - Functions: Use "cmd_{command}" for a {command} such as:
" command! -nargs=* {command} call s:cmd_{command}(<f-args>)
"
" - Functions: Use "complete_{type}" for :command-completion-custom or
" :command-completion-customlist functions.
"
" - Functions: Use "on_{event}_{mod}" for a handler of :autocmd {event}.
"
" - Use "tabpage" instead of "tab_page" or "tab page" or "tab".
"
" * Register usage:
"
" - "g for :global.
"
" - Don't overwrite other named registers.
" Basic "{{{1
" Absolute "{{{2
function! s:SID_PREFIX()
return matchstr(expand('<sfile>'), '<SNR>\d\+_')
endfunction
" Encoding "{{{2
set encoding=utf-8
if has('iconv')
let s:enc_euc = 'euc-jp'
let s:enc_jis = 'iso-2022-jp'
" Does iconv support JIS X 0213 ?
if iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'euc-jisx0213,euc-jp'
let s:enc_jis = 'iso-2022-jp-3'
endif
" Make fileencodings
let &fileencodings = 'ucs-bom'
if &encoding !=# 'utf-8'
let &fileencodings = &fileencodings . ',' . 'ucs-2le'
let &fileencodings = &fileencodings . ',' . 'ucs-2'
endif
let &fileencodings = &fileencodings . ',' . s:enc_jis
if &encoding ==# 'utf-8'
let &fileencodings = &fileencodings . ',' . s:enc_euc
let &fileencodings = &fileencodings . ',' . 'cp932'
elseif &encoding =~# '^euc-\%(jp\|jisx0213\)$'
let &encoding = s:enc_euc
let &fileencodings = &fileencodings . ',' . 'utf-8'
let &fileencodings = &fileencodings . ',' . 'cp932'
else " cp932
let &fileencodings = &fileencodings . ',' . 'utf-8'
let &fileencodings = &fileencodings . ',' . s:enc_euc
endif
let &fileencodings = &fileencodings . ',' . &encoding
unlet s:enc_euc
unlet s:enc_jis
endif
" Options "{{{2
if (1 < &t_Co || has('gui')) && has('syntax')
syntax enable
if !exists('g:colors_name') " Don't override colorscheme on reloading.
colorscheme nevfn
set background=dark
endif
endif
filetype plugin indent on
set ambiwidth=single
set autoindent
set backspace=indent,eol,start
set backup
set backupcopy&
set backupdir=~/tmp/vim
set backupskip&
set backupskip+=svn-commit.tmp,svn-commit.[0-9]*.tmp
if exists('+breakindent')
set breakindent
set breakindentopt=sbr,list:-1
endif
set cinkeys& cinkeys-=0#
set cinoptions=:0,t0,(0,W1s
set completeopt=menu
set directory=~/tmp/vim
set noequalalways
set expandtab
if exists('+fixendofline')
set nofixendofline
endif
set formatoptions=tcroqnlM1
let &formatlistpat = '\v^\s*('
\ .. join([
\ '(\d+|\a)\.',
\ '\(?(\d+|\a)\)',
\ '\[?(\d+|\a)\]',
\ '[*+-]'
\ ], '|')
\ .. ')\s*'
if exists('+fuoptions')
set fuoptions=maxhorz,maxvert
endif
if exists('+guicursor')
set guicursor&
set guicursor=a:blinkwait4000-blinkon1500-blinkoff500
endif
if exists('+guifont')
set guifont=Menlo\ Regular:h12 antialias
endif
if exists('+guioptions')
set guioptions=cgM
endif
set history=100
" Highlight matches. But:
" - Do not highlight matches according to the last session,
" - Keep highlighting before and after reloading vimrc.
if !v:vim_did_enter
set hlsearch
nohlsearch
endif
" set grepprg=... " See s:toggle_grepprg().
set incsearch
set laststatus=2 " always show status lines.
if exists('+macmeta')
set macmeta
endif
set modeline " Some distros disable this by default.
if has('gui_running')
set mouse=a
endif
set ruler
set showcmd
set showmode
set updatetime=4000
set tagcase=smart
set title
set titlestring=Vim:\ %f\ %h%r%m
if exists('+transparency')
set transparency=15
endif
set ttimeoutlen=50 " Reduce annoying delay for key codes, especially <Esc>...
set wildmenu
set viminfo=<50,'10,h,r/a,n~/.viminfo
" default 'statusline' with 'fileencoding'.
let &statusline = ''
let &statusline .= '%<%f %h%m%r%w'
let &statusline .= '%='
let &statusline .= '['
let &statusline .= '%{&l:fileencoding == "" ? &encoding : &l:fileencoding}'
let &statusline .= '%{&l:bomb ? "/BOM" : ""}'
let &statusline .= ']'
let &statusline .= '[%{&l:fileformat}]'
let &statusline .= ' %-14.(%l,%c%V%) %P'
function! s:my_tabline() "{{{
let s = ''
for i in range(1, tabpagenr('$'))
let bufnrs = tabpagebuflist(i)
let curbufnr = bufnrs[tabpagewinnr(i) - 1] " first window, first appears
let no = (i <= 10 ? i-1 : '#') " display 0-origin tabpagenr.
let mod = len(filter(bufnrs, 'getbufvar(v:val, "&modified")')) ? '+' : ' '
let title = s:gettabvar(i, 'title')
let title = title != '' ? title : fnamemodify(s:gettabvar(i, 'cwd'), ':t')
let title = title != '' ? title : fnamemodify(getcwd(), ':t')
let s .= '%'.i.'T'
let s .= '%#' . (i == tabpagenr() ? 'TabLineSel' : 'TabLine') . '#'
let s .= no
let s .= mod
let s .= title
let s .= '%#TabLineFill#'
let s .= ' '
endfor
let s .= '%#TabLineFill#%T'
let s .= '%=%#TabLine#'
let s .= '| '
let s .= '%999X'
let branch_name = g#branch#get_name(getcwd())
let s .= (branch_name != '' ? branch_name : '?')
let s .= '%X'
return s
endfunction "}}}
let &tabline = '%!' . s:SID_PREFIX() . 'my_tabline()'
if has('gui_running') && !v:vim_did_enter
if &columns < 161
set columns=161 " 80 + 1 + 80
end
set lines=999 " Maximize GUI window vertically
endif
let g:mapleader = ','
let g:maplocalleader = '.'
" Load plugins "{{{2
" Several plugins refer global variables which are set in this vimrc,
" but this vimrc are written with features which are provided by some plugins.
" So that plugins must be loaded at this timing, especially for <Leader>.
let s:my_after_path = split(&runtimepath, ',')[-1]
execute 'set runtimepath-='.s:my_after_path
packloadall " To autoload plugins while sourcing this vimrc.
execute 'set runtimepath+='.s:my_after_path
" Packages "{{{2
packadd! editorconfig
" Misc. "{{{2
" Use this group for any autocmd defined in this file.
augroup MyAutoCmd
autocmd!
augroup END
call altercmd#load()
call arpeggio#load()
if !isdirectory($HOME . '/tmp/vim')
call mkdir($HOME . '/tmp/vim', 'p', 0700)
endif
" Syntax "{{{1
" User-defined commands to extend Vim script syntax.
" - Place commands which are for interactive use at the bottom.
" FIXME: syntax highlighting
" FIXME: completion
" Stuffs "{{{2
let s:FALSE = 0
let s:TRUE = !s:FALSE
function! s:separate_list(list, regexp)
let i = 0
while i < len(a:list) && a:list[i] =~# a:regexp
let i += 1
endwhile
return [(0 < i ? a:list[:i-1] : []), a:list[(i):]]
endfunction
function! s:contains_p(list, regexp)
for item in a:list
if item =~# a:regexp
return s:TRUE
endif
endfor
return s:FALSE
endfunction
" :map wrappers "{{{2
" Allmap - :map in all modes "{{{3
command! -nargs=+ Allmap
\ execute 'map' <q-args>
\ | execute 'map!' <q-args>
\ | execute 'tmap' <q-args>
command! -nargs=+ Allnoremap
\ execute 'noremap' <q-args>
\ | execute 'noremap!' <q-args>
\ | execute 'tnoremap' <q-args>
command! -nargs=+ Allunmap
\ execute 'unmap' <q-args>
\ | execute 'unmap!' <q-args>
\ | execute 'tunmap' <q-args>
" Cmap - wrapper of :map to easily execute commands "{{{3
"
" :Cmap {lhs} {script}
" Other variants:
" Cmap!, Ccmap, Cimap, Clmap, Cnmap, Comap, Csmap, Cvmap, Cxmap,
" Callmap, Cobjmap.
"
" {lhs}
" Same as :map. As additional :map-arguments, <count> and <noexec> are
" available.
"
" <count>
" Whenever {script} are executed, count effect (e.g. typing "3:" will be
" treated as ":.,+2") is ignored unless <count> is specified.
"
" <noexec>
" If <noexec> is specified, {script} is just inserted in the
" Command-line, but it's not executed.
"
" {script}
" A script which is executed whenever key sequence {lhs} are typed.
command! -bang -nargs=* Cmap call s:cmd_Cmap('', '<bang>', [<f-args>])
command! -nargs=* Ccmap call s:cmd_Cmap('c', '', [<f-args>])
command! -nargs=* Cimap call s:cmd_Cmap('i', '', [<f-args>])
command! -nargs=* Clmap call s:cmd_Cmap('l', '', [<f-args>])
command! -nargs=* Cnmap call s:cmd_Cmap('n', '', [<f-args>])
command! -nargs=* Comap call s:cmd_Cmap('o', '', [<f-args>])
command! -nargs=* Csmap call s:cmd_Cmap('s', '', [<f-args>])
command! -nargs=* Cvmap call s:cmd_Cmap('v', '', [<f-args>])
command! -nargs=* Cxmap call s:cmd_Cmap('x', '', [<f-args>])
command! -nargs=* Callmap call s:cmd_Cmap('All', '', [<f-args>])
command! -nargs=* Cobjmap call s:cmd_Cmap('Obj', '', [<f-args>])
function! s:cmd_Cmap(prefix, suffix, args)
" FIXME: This parsing may not be compatible with the original one.
let [options, rest] = s:separate_list(a:args,
\ '^\c<\(buffer\|expr\|script\|silent\|special\|unique\|count\|noexec\)>$')
if len(rest) < 2
throw 'Insufficient number of arguments: ' . string(rest)
endif
let lhs = rest[0]
let script = rest[1:]
let count_p = s:contains_p(options, '^\c<count>$')
let noexec_p = s:contains_p(options, '^\c<noexec>$')
call filter(options, 'v:val !~# ''^\c<\(count\|noexec\)>$''')
execute a:prefix.'noremap'.a:suffix join(options) lhs
\ ':'.(count_p ? '' : '<C-u>') . join(script) . (noexec_p ? '' : '<Return>')
endfunction
" Fmap - wrapper of :map to easily call a function "{{{3
"
" :Fmap {lhs} {expression}
" Other variants:
" Fmap!, Fcmap, Fimap, Flmap, Fnmap, Fomap, Fsmap, Fvmap, Fxmap,
" Fallmap, Fobjmap.
"
" {lhs}
" Same as :map.
"
" {expression}
" An expression to call a function (without :call). This expression is
" executed whenever key sequence {lhs} are typed.
command! -bang -nargs=* Fmap call s:cmd_Fmap('', '<bang>', [<f-args>])
command! -nargs=* Fcmap call s:cmd_Fmap('c', '', [<f-args>])
command! -nargs=* Fimap call s:cmd_Fmap('i', '', [<f-args>])
command! -nargs=* Flmap call s:cmd_Fmap('l', '', [<f-args>])
command! -nargs=* Fnmap call s:cmd_Fmap('n', '', [<f-args>])
command! -nargs=* Fomap call s:cmd_Fmap('o', '', [<f-args>])
command! -nargs=* Fsmap call s:cmd_Fmap('s', '', [<f-args>])
command! -nargs=* Fvmap call s:cmd_Fmap('v', '', [<f-args>])
command! -nargs=* Fxmap call s:cmd_Fmap('x', '', [<f-args>])
command! -nargs=* Fallmap call s:cmd_Fmap('All', '', [<f-args>])
command! -nargs=* Fobjmap call s:cmd_Fmap('Obj', '', [<f-args>])
function! s:cmd_Fmap(prefix, suffix, args)
" FIXME: This parsing may not be compatible with the original one.
let [options, rest] = s:separate_list(a:args,
\ '^\c<\(buffer\|expr\|script\|silent\|special\|unique\)>$')
if len(rest) < 2
throw 'Insufficient number of arguments: ' . string(rest)
endif
let lhs = rest[0]
let rhs = rest[1:]
execute a:prefix.'noremap'.a:suffix join(options) lhs
\ ':<C-u>call' join(rhs) '<Return>'
endfunction
" Objmap - :map for text objects "{{{3
"
" Keys for text objects should be mapped in Visual mode and Operator-pending
" mode. The following commands are just wrappers to avoid DRY violation.
command! -nargs=+ Objmap
\ execute 'omap' <q-args>
\ | execute 'vmap' <q-args>
command! -nargs=+ Objnoremap
\ execute 'onoremap' <q-args>
\ | execute 'vnoremap' <q-args>
command! -nargs=+ Objunmap
\ execute 'ounmap' <q-args>
\ | execute 'vunmap' <q-args>
" Operatormap - :map for oeprators "{{{3
"
" Keys for operators should be mapped in Normal mode and Visual mode. The
" following commands are just wrappers to avoid DRY violation.
"
" FIXME: How about mapping to g@ in Operator-pending mode
" to use {operator}{operator} pattern?
command! -nargs=+ Operatormap
\ execute 'nmap' <q-args>
\ | execute 'vmap' <q-args>
command! -nargs=+ Operatornoremap
\ execute 'nnoremap' <q-args>
\ | execute 'vnoremap' <q-args>
command! -nargs=+ Operatorunmap
\ execute 'nunmap' <q-args>
\ | execute 'vunmap' <q-args>
" CD - alternative :cd with more user-friendly completion "{{{2
command! -complete=customlist,s:complete_cdpath -nargs=+ CD cd <args>
function! s:complete_cdpath(arglead, cmdline, cursorpos)
return split(globpath(&cdpath,
\ join(split(a:cmdline, '\s', s:TRUE)[1:], ' ') . '*/'),
\ "\n")
endfunction
AlterCommand cd CD
" Hecho, Hechon, Hechomsg - various :echo with highlight specification "{{{2
command! -bar -nargs=+ Hecho call s:cmd_Hecho('echo', [<f-args>])
command! -bar -nargs=+ Hechon call s:cmd_Hecho('echon', [<f-args>])
command! -bar -nargs=+ Hechomsg call s:cmd_Hecho('echomsg', [<f-args>])
function! s:cmd_Hecho(echo_command, args)
let highlight_name = a:args[0]
let messages = a:args[1:]
execute 'echohl' highlight_name
execute a:echo_command join(messages)
echohl None
endfunction
" KeyboardLayout - declare differences of logical and physical layouts "{{{2
"
" :KeyboardLayout {physical-key} {logical-key}
"
" Declare that whenever Vim gets a character {logical-key}, the
" corresponding physical key is {physical-key}. This declaration is useful
" to define a mapping based on physical keyboard layout.
"
" Example: Map the physical key {X} to {rhs}:
" noremap <Plug>(physical-key-{X}) {rhs}
command! -nargs=+ KeyboardLayout call s:cmd_KeyboardLayout(<f-args>)
function! s:cmd_KeyboardLayout(physical_key, logical_key)
let indirect_key = '<Plug>(physical-key-' . a:physical_key . ')'
execute 'Allmap' a:logical_key indirect_key
execute 'Allnoremap' indirect_key a:logical_key
endfunction
" Qexecute - variant of :execute with some extensions "{{{2
"
" Like :execute but all arguments are treated as single string like <q-args>.
" As an extension, "[count]" will be expanded to the currently given count.
command! -complete=command -nargs=* Qexecute call s:cmd_Qexecute(<q-args>)
function! s:cmd_Qexecute(script)
execute substitute(a:script, '\[count\]', s:count(), 'g')
endfunction
function! s:count(...)
if v:count == v:count1 " is count given?
return v:count
else " count isn't given. (the default '' is useful for special value)
return a:0 == 0 ? '' : a:1
endif
endfunction
" Source - wrapper of :source with echo. "{{{2
" FIXME: better name.
command! -bar -nargs=1 Source
\ echo 'Sourcing ...' expand(<q-args>)
\ | source <args>
\ | redraw
\ | echo 'Sourced ...' expand(<q-args>)
" SuspendWithAutomticCD "{{{2
" Assumption: Use tmux.
" Assumption: There is a window with the title "another".
function! s:is_tmux_available()
if has('gui_running')
return v:false
else
return $TMUX != ''
endif
endfunction
command! -bar -nargs=0 SuspendWithAutomticCD
\ call s:cmd_SuspendWithAutomticCD()
function! s:cmd_SuspendWithAutomticCD()
if s:is_tmux_available()
call s:activate_terminal()
" \025 = <C-u>
" \015 = <C-m>
" To avoid adding the cd script into the command-line history,
" there are extra leading whitespaces in the cd script.
let vim_cwd = fnamemodify(getcwd(), ':~')
let result = system(join([
\ 'tmux select-window -t another',
\ 'send-keys A C-u " " cd " " ' .. shellescape(vim_cwd) .. ' C-m',
\ ], ' \; '))
if result != ''
Hechomsg ErrorMsg result
endif
else
suspend
endif
endfunction
" TabpageTitle - name the current tabpage "{{{2
command! -bar -nargs=* TabpageTitle
\ if <q-args> == ''
\ | let t:title = input("Set tabpage's title to: ",'')
\ | else
\ | let t:title = <q-args>
\ | endif
" UsualDays - set up the layout of my usual days "{{{2
command! -bar -nargs=0 UsualDays call s:cmd_UsualDays()
function! s:cmd_UsualDays()
normal! 'T
execute 'CD' fnamemodify(expand('%'), ':p:h')
TabpageTitle meta
tabnew
normal! 'V
execute 'CD' fnamemodify(expand('%'), ':p:h:h:h')
TabpageTitle config
tabnew
normal! 'Y
execute 'CD' fnamemodify(expand('%'), ':p:h')
endfunction
" Utf8 and others - :edit with specified 'fileencoding' "{{{2
command! -bang -bar -complete=file -nargs=? Cp932
\ edit<bang> ++enc=cp932 <args>
command! -bang -bar -complete=file -nargs=? Eucjp
\ edit<bang> ++enc=euc-jp <args>
command! -bang -bar -complete=file -nargs=? Iso2022jp
\ edit<bang> ++enc=iso-2022-jp <args>
command! -bang -bar -complete=file -nargs=? Utf8
\ edit<bang> ++enc=utf-8 <args>
command! -bang -bar -complete=file -nargs=? Jis Iso2022jp<bang> <args>
command! -bang -bar -complete=file -nargs=? Sjis Cp932<bang> <args>
" Utilities "{{{1
" Font selector "{{{2
command! -complete=customlist,s:cmd_Font_complete -nargs=* Font
\ set guifont=<args>
function! s:cmd_Font_complete(arglead, cmdline, cursorpos)
" FIXME: Proper completion
return [
\ 'Ayuthaya:h14 antialias',
\ 'cinecaption:h16 antialias',
\ 'DejaVu\ Sans\ Mono:h14 antialias',
\ 'Droid\ Sans\ Mono:h14 antialias',
\ 'Monaco:h14 antialias',
\ 'Osaka-Mono:h15 antialias',
\ 'Osaka-Mono:h16 antialias',
\ 'PC98:h16 noantialias',
\ 'Source\ Code\ Pro:h14 antialias',
\ ]
endfunction
" Help-related stuffs "{{{2
function! s:helpbufwinnr()
let wn = 1
while wn <= winnr('$')
let bn = winbufnr(wn)
if getbufvar(bn, '&buftype') == 'help'
return [bn, wn]
endif
let wn = wn + 1
endwhile
return [-1, 0]
endfunction
function! s:close_help_window()
let [help_bufnr, help_winnr] = s:helpbufwinnr()
if help_bufnr == -1
return
endif
let current_winnr = winnr()
execute help_winnr 'wincmd w'
execute 'wincmd c'
if current_winnr < help_winnr
execute current_winnr 'wincmd w'
elseif help_winnr < current_winnr
execute (current_winnr-1) 'wincmd w'
else
" NOP
endif
endfunction
" High-level key sequences "{{{2
function! s:keys_to_complete()
if &l:filetype ==# 'vim'
return "\<C-x>\<C-v>"
elseif strlen(&l:omnifunc)
return "\<C-x>\<C-o>"
else
return "\<C-n>"
endif
endfunction
function! s:keys_to_escape_command_line_mode_if_empty(key)
if getcmdline() == ''
return "\<Esc>"
else
return a:key
end
endfunction
function! s:keys_to_insert_one_character()
Hecho ModeMsg '-- INSERT (one char) --'
return nr2char(getchar()) . "\<Esc>"
endfunction
function! s:keys_to_select_the_last_changed_text()
" It is not possible to determine whether the last operation to change text
" is linewise or not, so guess the wise of the last operation from the range
" of '[ and '], like wise of a register content set by setreg() without
" {option}.
let col_begin = col("'[")
let col_end = col("']")
let length_end = len(getline("']"))
let maybe_linewise_p = (col_begin == 1
\ && (col_end == length_end
\ || (length_end == 0 && col_end == 1)))
return '`[' . (maybe_linewise_p ? 'V' : 'v') . '`]'
endfunction
function! s:keys_to_stop_insert_mode_completion()
if pumvisible()
return "\<C-y>"
else
return "\<Space>\<BS>"
endif
endfunction
" Jump sections "{{{2
" for normal mode. a:pattern is '/regexp' or '?regexp'.
function! s:jump_section_n(pattern)
let pattern = a:pattern[1:]
let forward_p = a:pattern[0] == '/'
let flags = forward_p ? 'W' : 'Wb'
mark '
let i = 0
while i < v:count1
if search(pattern, flags) == 0
if forward_p
normal! G
else
normal! gg
endif
break
endif
let i = i + 1
endwhile
endfunction
" for visual mode. a:motion is '[[', '[]', ']]' or ']['.
function! s:jump_section_v(motion)
execute 'normal!' "gv\<Esc>"
execute 'normal' v:count1 . a:motion
let line = line('.')
let col = col('.')
normal! gv
call cursor(line, col)
endfunction
" for operator-pending mode. a:motion is '[[', '[]', ']]' or ']['.
function! s:jump_section_o(motion)
execute 'normal' v:count1 . a:motion
endfunction
" Sum numbers "{{{2
command! -bang -bar -nargs=* -range Sum
\ <line1>,<line2>call s:cmd_Sum(<bang>0, <f-args>)
function! s:cmd_Sum(banged_p, ...) range
let field_number = (1 <= a:0 ? a:1 : 1)
let field_separator = (2 <= a:0 ? a:2 : 0)
execute a:firstline ',' a:lastline '!awk'
\ (field_separator is 0 ? '' : '-F'.field_separator)
\ "'"
\ 'BEGIN {x = 0}'
\ '{x = x + $'.field_number '}'
\ '{if (\!' a:banged_p ') print $0}'
\ 'END {print x}'
\ "'"
endfunction
" Tabpage visit history "{{{2
autocmd MyAutoCmd TabEnter * let t:entered_at = reltime()
if !v:vim_did_enter
" TabEnter will never be triggered for the initial tabpage.
doautocmd MyAutoCmd TabEnter
endif
function! s:back_to_the_last_tabpage()
if tabpagenr('$') == 1
Hecho ErrorMsg 'There is only one tab page. Nowhere to back.'
return
endif
let tn = tabpagenr()
let xs = []
noautocmd tabdo call add(xs, [reltimestr(t:entered_at), tabpagenr()])
noautocmd execute 'normal!' tn . 'gt'
call remove(xs, tn - 1)
call sort(xs)
execute 'normal!' xs[-1][1] . 'gt'
endfunction
" Toggle options "{{{2
function! s:toggle_bell()
if &visualbell
set novisualbell t_vb&
echo 'bell on'
else
set visualbell t_vb=
echo 'bell off'
endif
endfunction
function! s:toggle_grepprg()
" Toggle, more precisely, rotate the value of 'grepprg'.
" If 'grepprg' has a value not listed in VALUES,
" treat VALUES[0] as the default/fallback value,
" and set 'grepprg' to the value.
let VALUES = ['git grep -n', 'internal']
let i = (index(VALUES, &grepprg) + 1) % len(VALUES)
let grepprg = &grepprg
let &grepprg = VALUES[i]
echo "'grepprg' =" &grepprg '(was' grepprg.')'
endfunction
if !v:vim_did_enter
" Set 'grepprg' to my default value. In this scope, 'grepprg' has Vim's
" default value and it differs from what I want to use. So that calling
" s:toggle_grepprg() at here does set 'grepprg' to my default value.
silent call s:toggle_grepprg()
if !has('unix')
" For non-*nix environments, git is not usually available. To avoid error
" and manual toggling, set 'grepprg' to my alternative value.
silent call s:toggle_grepprg()
endif
endif
function! s:toggle_option(option_name)
execute 'setlocal' a:option_name.'!'
execute 'setlocal' a:option_name.'?'
endfunction
" :WhatIDid "{{{2
command! -bar -nargs=0 WhatIDid call s:cmd_WhatIDid()
function! s:cmd_WhatIDid()
" Use the following command when git is fixed:
"
" $ git diff --name-only master... ':(exclude,attr:-diff)'
" fatal: BUG:tree-walk.c:946: unsupported magic 40
args `comm -23 <(git diff --name-only master...) <(git ls-files ':(attr:-diff)')`
endfunction
" Window-related stuffs "{{{2
" Are the windows :split'ed and :vsplit'ed?
function! s:windows_jumbled_p()
" Calculate the terminal height by some values other than 'lines'.
" Don't consider about :vsplit.
let calculated_height = &cmdheight
let winid = winnr('$')
while 0 < winid
let calculated_height += 1 " statusline
let calculated_height += winheight(winid)
let winid = winid - 1
endwhile
if &laststatus == 0
let calculated_height -= 1
elseif &laststatus == 1 && winnr('$') == 1
let calculated_height -= 1
else " &laststatus == 2