1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 " Multi-version vimrc compatible with version 4 and above. vim:set fdm=marker:
3 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5 " Note that "if <condition> | call Something() | endif" syntax is unsupported
6 " in Vim 4 so we write all our functions out the long way. It does work in
7 " autocommand definitions, however.
9 " Vim 4 complains if version isn't set in the configuration file.
12 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
13 " Handle options safe to use in version 4. Vim 4 parses but ignores the
14 " "if version" syntax used later in this file so we don't use it. No attempt
15 " is made to make this configuration compatible with Vim 3.
16 " Some of these settings should strictly be wrapped inside "if has()" blocks
17 " but that would cause them not to be ignored by Vim 4.
18 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
20 " No compatibility mode.
25 " And use spaces not tabs.
27 " And << and >> indent by 2.
29 " Backspace deletes full tab width at the start of a line.
32 " Allow backspace to delete before start of line.
35 " Don't jump to the start of the line when using H, L etc.
40 " Show partial commands in the ruler.
42 " And always show the status line.
47 se cinkeys=0{,0},0),:,!^F,o,O,e
53 " Don't be bugged by messages at the bottom of the screen.
59 " Case-insensitive search.
61 " But override by typing capitals.
64 " Look for ctags in home directory first.
65 se tags=~/.tags,./tags,tags
67 " Don't timeout waiting to interpet, eg, <ESC>OA as an escape code.
70 " Use ^B to search backward when completing.
72 " Use ^L to show matching completions but don't select one.
73 inoremap <C-l> <C-n><C-p>
81 if (has("win32") || has("win64")) && version >= "504"
82 se rtp=~/.vim,$VIMRUNTIME
85 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
86 " Handle options only available in Vim 5 and above.
87 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
88 if version >= "500" "{{{1
91 " Tell Vim we use dark backgrounds in our terminals.
92 if ! has("gui_running")
96 " Allow mouse use in a terminal but only if it can work.
97 if has("xterm_clipboard")
101 " Update more quickly. For use with sign highlighting as polling for
102 " CursorMove makes redrawing slow.
107 " Enable tab-completion prompting for commands.
110 " Don't list object files when globbing files to load.
111 se wildignore+=*.o,*.obj
112 " So there's no need to assign them low priority.
113 se suffixes-=*.o,*.obj
116 " Save sessions in UNIX format with / as file separator. This is
122 " How often do we need to use ^A/^X on octals?
125 " Nuke any pre-existing autocommands.
142 " Save the current window dimensions so we can restore them when we quit.
143 if ! exists("g:oldcols")
144 let g:oldcols=&columns
146 if ! exists("g:oldlines")
147 let g:oldlines=&lines
150 " More GUI options. Add icon and tearoffs.
156 " Allow dynamic window resize even if we aren't in an xterm.
157 se t_WS=
\e[8;%p1%d;%p2%dt
159 " Highlight search results.
160 if has("extra_search")
164 " Syntax highlighting. New versions will use syn enable instead.
169 if has("user_commands")
176 " Forget the Ex mode mapping.
180 " Position the compview plugin window.
181 au Display BufEnter -SearchResults- set buftype=nowrite | set nonumber | wincmd J
185 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
186 " Handle options only available in Vim 5.2 and above.
187 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
188 if version >= "502" "{{{1
191 " Helper to initialise a variable.
192 fun! Prep_Var(var, value) "{{{2
196 exe "let " . a:var . "=" . a:value
199 " Set up our variables.
200 fun! Iain_Vars() "{{{2
201 call Prep_Var("w:iainlist", 0)
202 call Prep_Var("b:iainhex", 0)
203 call Prep_Var("b:iainverbose", 0)
204 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
205 call Prep_Var("b:iainstatus", "'Fih'")
206 call Prep_Var("g:iainextracolumnsnumber", "''")
207 call Prep_Var("g:iainextracolumnslist", "''")
208 call Prep_Var("b:iaincul", 0)
209 call Prep_Var("b:iainalt", 0)
211 call Prep_Var("g:marksigns", 0)
212 call Prep_Var("g:firstsign", 100)
214 call Prep_Var("g:resizable", "''")
217 " Show the window title.
218 fun! Show_TitleString() "{{{2
222 " Vim 5 doesn't have printf.
225 let l:ts1=" " . l:ts1
227 let l:ts1=l:ts1 . ": " . expand('%t')
229 let l:ts1=l:ts1 . " (" . getcwd() . ")"
230 if has("clientserver")
231 let l:ts1=l:ts1 . " " . v:servername
236 " Toggle case-sensitivity.
237 fun! Invert_Case() "{{{2
241 " Can we resize this window?
242 fun! Can_Resize() "{{{2
245 if g:resizable == "0" || g:resizable == "1"
249 " Do we KNOW we can(not) resize?
250 if has("gui_running")
252 elseif $RESIZABLE == &term
254 elseif $RESIZABLE == "0"
257 " Assume we can. Allow overriding.
263 " Grow or shrink the window width.
264 fun! Resize_Columns(op, ...) "{{{2
274 " Vim 5 hardcodes the size of numbers column to 8.
275 if version >= "700" && has("linebreak")
276 let l:columns = &numberwidth
284 exe "let l:resize=" . &columns . a:op . l:columns
285 let l:resize = "se columns=" . l:resize
287 " HACK: Inside screen there is an extra line for the status bar. Vim
288 " manages the resize by sending an escape sequence to set the number of
289 " lines and number of columns in one action. To do this it will first query
290 " the number of lines and then set <same number of lines> by <new number of
291 " columns>. Because of the extra line for the status bar this results in
292 " the real terminal being shrunk by a line. We ask for the terminal to grow
293 " by a line so it ends up actually being the same.
294 if &term =~ '^screen'
295 let l:resize = l:resize . " lines=" . (&lines + 1)
301 " Grow or shrink the window height.
302 fun! Resize_Lines(op, lines) "{{{2
311 exe "let l:resize=" . &lines . a:op . a:lines
312 if &term =~ '^screen'
313 let l:resize = l:resize + 1
315 let l:resize = "se lines=" . l:resize
320 " Set extra columns depending on window status.
321 fun! Extra_Columns(extra, var, ...) "{{{2
322 " Vim 6 doesn't have winnr("$"). Determine which windows are open
323 " ourselves by using :windo to incremement a counter. As Vim 5
324 " doesn't have :windo we require Vim 6 for this.
332 " Remember which window we're in.
333 let l:winnr = winnr()
334 let l:num_windows = 0
335 windo let l:num_windows = l:num_windows + 1
336 " Switch back to the window we were in.
337 exe l:winnr . "wincmd w"
344 let l:condition = a:1
350 while l:n < l:num_windows
351 " If window w exists then getwinvar(w, "&modified") will be 0 or 1.
352 if getwinvar(l:i, "&modified") =~ '^\d'
356 exe "if getwinvar(" . l:i . ", '" . a:var . "') " . l:condition . " | let l:val = 1 | endif"
358 exe "let l:windows = '" . l:windows . ":" . l:i . "'"
364 let l:extra = "g:iainextracolumns" . a:extra
365 exe "let l:val = " . l:extra
366 exe "let " . l:extra . " = '" . l:windows . "'"
368 if l:windows == l:val
379 " Toggle number display.
380 fun! Number(resize) "{{{2
382 let &number = ! &number
384 " Ensure we keep track of any extra columns even if we aren't resizing.
385 " This prevents confusion when number is set at startup.
386 let l:extra = Extra_Columns("number", "&number")
389 call Resize_Columns(l:extra)
393 " Restore window size.
394 if has("autocmd") && ! has("gui_running")
395 au Display VimLeave * if exists("g:oldcols") | call Resize_Columns("-", (&columns - g:oldcols)) | endif
396 au Display VimLeave * if exists("g:oldlines") | call Resize_Lines("-", (&lines - g:oldlines)) | endif
401 au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif
402 au Mode BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
405 " Entering Make mode.
406 fun! MakeMode_map() "{{{2
415 fun! MakeMode_unmap() "{{{2
421 " Function to create mappings with either a hardcoded \ or <Leader>.
422 fun! Mapping(keysequence,mapping) "{{{2
424 exec "map \\" . a:keysequence . " " . a:mapping
426 exec "map <Leader>" . a:keysequence . " " . a:mapping
430 " Use - and = to create underlines.
431 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
432 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
434 " Change to ts=2 with \2.
435 call Mapping("2", ":se ts=2<CR>:<CR>")
436 " Change to ts=4 with \4.
437 call Mapping("4", ":se ts=4<CR>:<CR>")
438 " Change to ts=8 with \8.
439 call Mapping("8", ":se ts=8<CR>:<CR>")
440 " Change to ts=16 with \6.
441 call Mapping("6", ":se ts=16<CR>:<CR>")
442 " Change to ts=32 with \3.
443 call Mapping("3", ":se ts=32<CR>:<CR>")
444 " Toggle paste mode with \p.
445 call Mapping("p", ":se paste!<CR>:<CR>")
446 " Swap case-sensitivity with \c.
447 call Mapping("C", ":call Invert_Case()<CR>:<CR>")
448 " Change number mode with \n.
449 call Mapping("n", ":call Number(1)<CR>:<CR>")
450 " Expand or shrink window size with \> and \<.
451 call Mapping(">", ":call Resize_Columns('+')<CR>:<CR>")
452 call Mapping("<", ":call Resize_Columns('-')<CR>:<CR>")
453 " Clear search pattern with \/.
454 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
455 " Toggle alternate buffer name with \#.
456 call Mapping("#", ":call Cycle_Alt()<CR>:<CR>")
458 " Set graphical window title.
459 if has("win32") || has("win64")
460 " Windows taskbar entries are probably too small to show full titles.
463 se titlestring=%{Show_TitleString()}
466 " Vim tip 99: What's the highlighting group under the cursor?
467 call Mapping("h", ":echo \"hi<\" . synIDattr(synID(line(\".\"),col(\".\"),1),\"name\") . '> trans<' . synIDattr(synID(line(\".\"),col(\".\"),0),\"name\") . \"> lo<\" . synIDattr(synIDtrans(synID(line(\".\"),col(\".\"),1)),\"name\") . \">\"<CR>")
469 fun! Uncluttered_Buffer() "{{{2
470 if exists("uncluttered_buffer")
471 if uncluttered_buffer == 1
490 if &ft == 'gitcommit'
497 fun! Startup_Resize() "{{{2
500 " Resize for numbers.
502 if version >= "700" && has("linebreak")
503 let l:columns = &numberwidth
513 let l:columns = l:columns + 2
518 if g:oldcols < (80 + l:columns)
519 call Resize_Columns("+", l:columns)
523 " Change status bar colour when various things happen.
524 " Flags: H/h: Cursor held/moved.
525 " F/f: Focus gained/lost.
526 " I/i: Insert mode entered/left.
527 fun! Highlight_StatusLine(flag) "{{{2
528 if ! has("statusline")
531 " Get current status.
534 " Change the status based on the flag. XXX: Does Vim let us to do flags?
537 let b:iainstatus = substitute(b:iainstatus, a:flag, a:flag, "")
540 let l:normalcolour = "darkblue"
541 let l:editingcolour = "darkmagenta"
542 let l:warningcolour = "darkred"
543 let l:readonlycolour = "red"
546 let l:colour = l:normalcolour
547 " Maybe override depending on status.
548 if b:iainstatus =~# "H"
549 if b:iainstatus =~# "I"
550 " Held in insert mode. Add extra highlight if we don't have focus.
551 if b:iainstatus =~# "f"
552 let l:colour = l:warningcolour
554 let l:colour = l:editingcolour
558 if b:iainstatus =~# "I"
559 " Regular insert mode.
560 let l:colour = l:editingcolour
564 " Override again if readonly.
565 if l:colour != l:normalcolour
566 if getbufvar("", "&ro")
567 let l:colour = l:readonlycolour
571 let l:termcolour = Iain_Colour(l:colour)
573 exec "highlight StatusLine gui=none term=none cterm=none guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
574 exec "highlight User1 gui=bold term=bold cterm=bold guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
577 fun! Iain_Colour(colour) "{{{2
579 if a:colour == "darkblue"
581 elseif a:colour == "darkmagenta"
583 elseif a:colour == "darkred"
585 elseif a:colour == "red"
589 if a:colour == "darkblue"
591 elseif a:colour == "darkmagenta"
593 elseif a:colour == "darkred"
595 elseif a:colour == "red"
604 au StatusLine VimEnter * call Highlight_StatusLine("")
606 " Show numbers by default.
607 au Display VimEnter * if ! Uncluttered_Buffer() | call Number(0) | endif
611 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
612 " Handle options only available in Vim 5.4 and above.
613 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
614 if version >= "504" "{{{1
617 " Reuse windows when using sbuffer.
620 " Do we have Unicode?
621 fun! Has_Unicode() "{{{2
622 if ! has('multi_byte')
630 if &tenc =~? '^u\(tf\|cs\)'
634 if ! strlen(&tenc) && &enc =~? '^u\(tf\|cs\)'
641 " Helper for status line.
642 " Show space, underscore or dollar sign depending on list mode.
643 fun! Show_List() "{{{2
665 " Helper for status line.
666 " Show c or C to denote case-sensitivity.
667 fun! Show_Case() "{{{2
675 " Helper for status line.
676 " Show the size of the tabstop.
677 fun! Show_Tabstop() "{{{2
681 " Helper for status line.
682 " Show p when paste mode is on.
683 fun! Show_Paste() "{{{2
691 " Helper for status line.
692 " Show v when virtualedit mode is block, insert or onemore.
693 " Show V when virtualedit mode is all.
694 fun! Show_VirtualEdit() "{{{2
695 if ! has("virtualedit")
708 " Helper for status line.
709 " Show U when persistent undo is on.
710 " Show u when persistent undo is off but an undofile exists.
711 fun! Show_Undo() "{{{2
712 if ! exists("&undofile")
718 elseif filereadable(undofile(expand("%")))
725 " Helper for status line.
726 " Show alternate buffer number and name.
727 fun! Show_Alt() "{{{2
728 let l:alt = bufnr("#")
729 if l:alt < 0 || l:alt == bufnr("") || ! b:iainalt
733 return " " . l:alt . ": " . expand("#:t")
736 " Helper for status line.
737 " Show scrollbind or cursorbind.
738 fun! Show_Bind() "{{{2
757 " Show the status line.
758 fun! Show_StatusLine() "{{{2
759 if ! has("statusline")
763 let l:sl1='%2n\:\ %<%1*%f%0*\ [%{Show_List()}%{Show_Bind()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%{Show_VirtualEdit()}%{Show_Undo()}%Y%M%R]%{Show_Alt()}\ '
764 let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%V%0*\ \|\ %P'
767 let l:hexformat='0\x%02B'
770 let l:sl1=l:sl1 . v:version . '\ %='
771 let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
773 let l:sl1=l:sl1 . '%='
776 exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
779 " Show the status line for the first time.
780 call Show_StatusLine()
783 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
784 " Handle options only available in Vim 6 and above.
785 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
786 if version >= "600" "{{{1
793 " Remember quickfix state.
798 " Set indenting by filetype.
801 " Less intrusive syntax highlighting.
807 if has("gui_running")
808 if has("win32") || has("win64")
809 exe "silent se guifont=DejaVu_Sans_Mono:h10:cANSI"
811 exe "silent se guifont=DejaVu\\ Sans\\ Mono\\ 10"
814 if has("gui_running") || &t_Co > 16
815 exe "silent colo iain"
818 " Ignore whitespace when diffing.
820 se diffopt=filler,iwhite
825 " Remember that we are opening the quickfix window.
826 au Mode BufWinEnter quickfix let g:quickfixing=1
827 au Mode BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
830 " Allow in-place editing of crontabs.
831 au Mode FileType crontab set backupcopy=yes
834 " Make * and # work the way you expect in visual mode.
835 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
836 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
838 " Set mark and update highlighting.
840 au Signs BufReadPost * call <SID>Highlight_Signs()
841 au Signs CursorHold * call <SID>Highlight_Signs()
844 " Helper to set buffer variable for a given sign.
845 fun! <SID>Prep_Sign(sign) "{{{2
846 if ! exists("b:sign" . a:sign) || ! g:marksigns
847 exe "let b:sign" . a:sign . "=0"
851 fun! <SID>Place_Sign(number, line, old, name) "{{{2
856 exe "sign unplace " . (g:firstsign + a:number) . " buffer=" . bufnr("")
857 " Don't place the sign if it would conflict with the last change sign.
858 exe "sign place " . (g:firstsign + a:number) . " line=" . a:line . " name=" . a:name . " buffer=" . bufnr("")
862 fun! <SID>Highlight_Signs(...) "{{{2
863 if ! has("signs") || ! g:marksigns || Uncluttered_Buffer()
867 let l:signs = g:iainsigns
870 while strlen(l:signs)
871 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+')
873 let l:name = substitute(l:sign, '[:.=-].*', "", "")
874 let l:var = tolower(l:name)
875 let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "")
876 let l:ascii = matchstr(l:sign, '^:.')
877 let l:mark = substitute(l:sign, '^\(:.\)*[.=-]', "", "")
879 let l:ascii = substitute(l:ascii, '^:', "", "")
883 let l:ascii = substitute(l:ascii, '"', '\\"', "")
885 call <SID>Prep_Sign(l:var)
886 exe "let " . l:var . " = <SID>Place_Sign(" . l:i . ", line(\"'" . l:ascii . "\"), b:sign" . l:var . ", \"Mark" . l:name . "\")"
889 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
894 fun! <SID>Cycle_Signs(resize) "{{{2
899 let g:marksigns = ! g:marksigns
901 " Retrofit arrays on to Vim 6.
902 if ! exists("g:iainsigns")
903 " Signs are defined in g:iainsigns. The syntax is as follows:
905 " Sign ::= Name (':' Mark)* Type Symbol
906 " Type ::= '=' | '-' | '.'
908 " Signs with Type '=' will be highlighted with the MarkSign group.
909 " Signs with Type '-' will be highlighted with the MarkLine group.
910 " Signs with Type '.' will be highlighted with the MarkDot group.
911 " Define the Mark where Symbol is not also the mark name, eg "']".
913 let g:iainsigns = "Dash:'=’ Dot:..• Quote:\"=” Caret:^.ʌ"
915 let g:iainsigns = "Dash=' Dot:..* Quote=\" Caret.^"
917 let g:iainsigns = g:iainsigns . " Less=< Greater=> Left=( Right=) SquareLeft=[ SquareRight=] BraceLeft={ BraceRight=} a-a b-b c-c d-d e-e f-f A-A B-B C-C D-D E-E F-F"
921 " Signs to highlight marks.
922 " Syntax won't work properly in Vim 6.
923 let l:signs = g:iainsigns
925 while strlen(l:signs)
926 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+')
928 let l:sign = substitute(l:sign, ':.', "", "")
929 let l:sign = substitute(l:sign, '=', " texthl=MarkSign text=", "")
930 let l:sign = substitute(l:sign, '\.', " texthl=MarkDot text=", "")
931 let l:sign = substitute(l:sign, '-', " texthl=MarkLine linehl=MarkLine text=", "")
933 exe "sign define Mark" . l:sign
935 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
939 call Resize_Columns("+", 2)
941 call <SID>Highlight_Signs()
945 exe "sign unplace " . (g:firstsign + l:i)
949 let l:signs = g:iainsigns
951 while strlen(l:signs)
952 let l:sign = matchstr(l:signs, '^[A-Za-z]\+')
954 exe "sign undefine Mark" . l:sign
955 call <SID>Prep_Sign(tolower(l:sign))
956 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
960 call Resize_Columns("-", 2)
966 fun! Cycle_List() "{{{2
967 " Pretty UTF-8 listchars.
969 let basic='tab:»·,trail:…,extends:«,precedes:»'
972 let basic=basic . ',nbsp:•'
975 let basic='tab:\\_,trail:_,extends:<,precedes:>'
978 let basic=basic . ',nbsp:+'
982 let w:iainlist = w:iainlist + 1
988 elseif w:iainlist == 1
989 exec "setlocal lcs=" . basic
992 exec "setlocal lcs=" . basic . "," . eol
996 call Resize_Columns(Extra_Columns("list", "iainlist", " == 2"), 1)
997 call Extra_Whitespace_Match()
1000 " Cycle between hex and decimal display of toolbar stuff.
1001 fun! Cycle_HexStatusLine() "{{{2
1003 let b:iainhex = ! b:iainhex
1004 call Show_StatusLine()
1007 " Cycle verbose display of toolbar stuff.
1008 fun! Cycle_VerboseStatusLine() "{{{2
1010 let b:iainverbose = ! b:iainverbose
1011 call Show_StatusLine()
1014 " Toggle quickfix window.
1015 fun! Cycle_Quickfix() "{{{2
1016 if ! has("quickfix")
1019 if g:quickfixing == 1
1027 " Toggle showing alternate buffer information.
1028 fun! Cycle_Alt() "{{{2
1030 let b:iainalt = ! b:iainalt
1031 call Show_StatusLine()
1034 " To be overridden later if applicable.
1035 fun! Extra_Whitespace_Match() "{{{2
1039 " Swap hex/decimal statusline with \x.
1040 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
1041 " Change statusline verbosity with \v.
1042 call Mapping("V", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
1043 " Cycle list styles with \l.
1044 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
1045 " Toggle tags with \t.
1046 call Mapping("t", ":Tlist<CR>")
1047 " Change foldmethod with \f.
1048 call Mapping("f", ":se foldenable!<CR>:<CR>")
1049 " Toggle quickfix window with \q.
1050 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
1051 " Rerun filetype detection with \s. The s is for syntax, as this will be
1052 " updated as a side-effect.
1053 call Mapping("S", ":filetype detect<CR>:<CR>")
1054 " Toggle marks with \m.
1055 call Mapping("m", ":call <SID>Cycle_Signs(1)<CR>:<CR>")
1058 " Show signs by default.
1059 au Display VimEnter * call <SID>Cycle_Signs(0)
1063 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1064 " Handle options only available in Vim 7 and above.
1065 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1066 if version >= "700" "{{{1
1069 " Helper to show tab name.
1070 fun! <SID>TabName(label, gui) "{{{2
1071 let l:label = a:label
1073 let l:label = "No Name"
1075 let l:label = "[" . l:label . "]"
1078 let l:label = fnamemodify(l:label, ":t")
1079 if strlen(l:label) >= 18
1080 let l:label = l:label[0:17] . ".."
1086 " Find out if any buffer was modified.
1087 fun! <SID>TabModified(buflist) "{{{2
1089 while l:i < len(a:buflist)
1090 if getbufvar(a:buflist[l:i], "&modified") == 1
1099 fun! Show_TabLine() "{{{2
1100 let l:s = "%#TabLineFill#Tabs:"
1103 while l:i < tabpagenr("$")
1106 let l:buflist = tabpagebuflist(l:i)
1107 let l:winnr = tabpagewinnr(l:i)
1108 let l:n = tabpagewinnr(l:i, "$")
1109 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 0)
1110 let l:modified = <SID>TabModified(l:buflist)
1112 " Choose highlighting.
1113 if l:i == tabpagenr()
1114 let l:s .= "%#TabLineSel#[" . l:n . l:modified . " " . l:label . "]"
1116 let l:s .= "%#TabLine# " . l:n . l:modified . " " . l:label . " "
1121 let l:s .= "%#TabLine#%T"
1125 " Per tab label for the GUI.
1126 fun! Show_GUITabLine() "{{{2
1127 let l:buflist = tabpagebuflist(v:lnum)
1128 let l:winnr = tabpagewinnr(v:lnum)
1129 let l:s = tabpagewinnr(v:lnum, "$")
1130 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 1)
1131 let l:modified = <SID>TabModified(l:buflist)
1133 let l:s .= l:modified . " " . l:label
1137 " Toggle highlighting cursor line when focus changes.
1138 fun! <SID>ToggleCursorLine() "{{{2
1141 if b:iainstatus =~# "H" && b:iainstatus =~# "I"
1142 " We are held in insert mode.
1143 if b:iainstatus =~# "f"
1144 " And focus was lost.
1145 let b:iaincul = getbufvar("", "&cursorline")
1148 setlocal nocursorline
1153 " Handle searching in a BufExplorer window.
1154 fun! <SID>BufExplorer_Search(n) "{{{2
1156 let l:re = '^ *\d %'
1158 let l:re = "^ *" . a:n
1161 " Find matching line.
1162 let l:line = search(l:re, 'w')
1171 " Peek ahead to the next matching line.
1172 let l:next = search(l:re, 'w')
1174 " Select the buffer if the match is unambiguous.
1181 call cursor(l:line, 0)
1184 " Entering a BufExplorer window.
1185 fun! <SID>BufExplorer_Map() "{{{2
1186 for l:n in [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ]
1187 exec "nnoremap <buffer> <silent>" . l:n . " :call <SID>BufExplorer_Search(" . l:n . ")<CR>"
1192 se tabline=%!Show_TabLine()
1193 se guitablabel=%!Show_GUITabLine()
1197 au StatusLine CursorHoldI * call Highlight_StatusLine("H")
1198 au StatusLine CursorMovedI * call Highlight_StatusLine("h")
1199 au StatusLine FocusGained * call Highlight_StatusLine("F")
1200 au StatusLine FocusLost * call Highlight_StatusLine("f")
1201 au StatusLine InsertEnter * call Highlight_StatusLine("I")
1202 au StatusLine InsertLeave * call Highlight_StatusLine("i")
1205 au Display FocusGained,FocusLost * call <SID>ToggleCursorLine()
1209 au Signs InsertEnter * call <SID>Highlight_Signs()
1210 au Signs InsertLeave * call <SID>Highlight_Signs()
1213 au Mode BufEnter \[BufExplorer\] call <SID>BufExplorer_Map()
1216 " Limit the size of the popup menu when completing.
1217 if has("insert_expand")
1221 " Make diffs vertical by default.
1223 se diffopt+=vertical
1226 " Set size of numbers column.
1231 " Add "previous tab" mapping as gb.
1232 map gb :tabprevious<CR>:<CR>
1235 if has("gui_macvim")
1239 " Yet more GUI options. Add tabs.
1245 let g:p4EnableMenu=1
1246 let g:p4Presets='P4CONFIG'
1249 let g:bufExplorerShowRelativePath=1
1250 let g:bufExplorerSplitOutPathName=0
1253 let g:NERDSpaceDelims=1
1256 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1257 " Handle options only available in Vim 7.2 and above.
1258 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1259 if version >= "702" "{{{1
1261 " http://vim.wikia.com/wiki/Highlight_unwanted_spaces
1262 augroup WhitespaceMatch
1264 au Display BufWinEnter * call Extra_Whitespace_Match()
1265 au Display Syntax * call Extra_Whitespace_Match()
1266 au Display BufWinLeave * call clearmatches()
1269 fun! Extra_Whitespace_Match() "{{{2
1271 " $ <before end of line>
1272 " \@<! <unless preceded by>
1273 " \%# <cursor position, ie when typing>
1274 let l:pattern = '\s\+\%#\@<!$'
1275 " Don't match single space in first column of diff.
1276 if &ft =~# '^diff$\|git'
1277 " \@! <unless also matching>
1278 " \(^\s$\) <a single whitespace>
1279 let l:pattern = '\(^\s$\)\@!' . l:pattern
1282 let l:hl = 'ctermfg=red guifg=red'
1284 " Underline if we aren't using listchars.
1285 let l:hl = l:hl . ' cterm=underline gui=underline'
1287 highlight clear ExtraWhitespace
1288 exe "highlight ExtraWhitespace " . l:hl
1289 if exists('w:whitespace_match_number')
1291 call matchdelete(w:whitespace_match_number)
1294 call matchadd('ExtraWhitespace', l:pattern, 10, w:whitespace_match_number)
1296 let w:whitespace_match_number = matchadd('ExtraWhitespace', l:pattern)
1300 call Extra_Whitespace_Match()
1305 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1306 " Handle options only available in Vim 7.3 and above.
1307 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1308 if version >= "703" "{{{1
1311 " Toggle persistent undo with \u.
1312 call Mapping("u", ":call <SID>Cycle_Undo()<CR>:<CR>")
1313 " Remove persistent undo file with \U.
1314 call Mapping("U", ":call <SID>Clear_Undo()<CR>:<CR>")
1316 " Use a persistent undo file if it exists.
1317 fun! <SID>Check_Undo() "{{{2
1318 if filereadable(undofile(expand("%")))
1323 " Toggle persistent undo for this buffer.
1324 fun! <SID>Cycle_Undo() "{{{2
1325 if has("persistent_undo")
1326 let &undofile = ! &undofile
1330 " Remove the persistent undo file for this buffer.
1331 fun! <SID>Clear_Undo() "{{{2
1332 if ! has("persistent_undo")
1338 let l:f = expand("%")
1343 let l:u = undofile(l:f)
1348 if ! filereadable(l:u) || ! filewritable(l:u)
1355 " Toggle ColorColumn at cursor position.
1356 fun! <SID>Cycle_ColorColumn() "{{{2
1361 let l:cc = &colorcolumn
1362 let l:column = col(".")
1363 let l:re = ",*\\<" . l:column . "\\>"
1365 let l:cc = substitute(l:cc, l:re, "", "g")
1367 let l:cc = l:cc . "," . l:column
1369 let &colorcolumn = substitute(l:cc, "^,*", "", "")
1373 " Enable showing ColorColumn at cursor position with \CC.
1374 call Mapping("CC", ":call <SID>Cycle_ColorColumn()<CR>:<CR>")
1375 " Remove last shown ColorColumn with \Cc.
1376 call Mapping("Cc", ":let &colorcolumn=substitute(&colorcolumn, \",*[0-9]*$\", \"\", \"\")<CR>:<CR>")
1377 " Remove all ColorColumns with \Cx.
1378 call Mapping("Cx", ":se colorcolumn=<CR>:<CR>")
1381 " Use persistent undo if available.
1383 if has("persistent_undo")
1384 au File BufReadPost * call <SID>Check_Undo()
1387 if has("cursorbind")
1388 au Display WinEnter * if &diff | se cursorbind | endif
1393 " Resize after startup.
1394 if version >= "500" "{{{1
1396 au Display VimEnter * call Startup_Resize()