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>
79 " Select previous widnow.
81 noremap <C-w><C-^> <C-w>p
85 if (has("win32") || has("win64")) && version >= "504"
86 se rtp=~/.vim,$VIMRUNTIME
89 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
90 " Handle options only available in Vim 5 and above.
91 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
92 if version >= "500" "{{{1
95 " Tell Vim we use dark backgrounds in our terminals.
96 if ! has("gui_running")
100 " Allow mouse use in a terminal but only if it can work.
101 if has("xterm_clipboard")
105 " Update more quickly. For use with sign highlighting as polling for
106 " CursorMove makes redrawing slow.
111 " Enable tab-completion prompting for commands.
114 " Don't list object files when globbing files to load.
115 se wildignore+=*.o,*.obj
116 " So there's no need to assign them low priority.
117 se suffixes-=*.o,*.obj
120 " Save sessions in UNIX format with / as file separator. This is
126 " How often do we need to use ^A/^X on octals?
129 " Nuke any pre-existing autocommands.
146 " Save the current window dimensions so we can restore them when we quit.
147 if ! exists("g:oldcols")
148 let g:oldcols=&columns
150 if ! exists("g:oldlines")
151 let g:oldlines=&lines
154 " More GUI options. Add icon and tearoffs.
160 " Allow dynamic window resize even if we aren't in an xterm.
161 se t_WS=
\e[8;%p1%d;%p2%dt
163 " Highlight search results.
164 if has("extra_search")
168 " Syntax highlighting. New versions will use syn enable instead.
173 if has("user_commands")
180 " Forget the Ex mode mapping.
184 " Position the compview plugin window.
185 au Display BufEnter -SearchResults- set buftype=nowrite | set nonumber | wincmd J
189 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
190 " Handle options only available in Vim 5.2 and above.
191 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
192 if version >= "502" "{{{1
195 " Helper to initialise a variable.
196 fun! Prep_Var(var, value) "{{{2
200 exe "let " . a:var . "=" . a:value
203 " Set up our variables.
204 fun! Iain_Vars() "{{{2
205 call Prep_Var("w:iainlist", 0)
206 call Prep_Var("b:iainhex", 0)
207 call Prep_Var("b:iainverbose", 0)
208 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
209 call Prep_Var("b:iainstatus", "'Fih'")
210 call Prep_Var("g:iainextracolumnsnumber", "''")
211 call Prep_Var("g:iainextracolumnslist", "''")
212 call Prep_Var("b:iaincul", 0)
213 call Prep_Var("b:iainalt", 0)
215 call Prep_Var("g:marksigns", 0)
216 call Prep_Var("g:firstsign", 100)
218 call Prep_Var("g:resizable", "''")
221 " Show the window title.
222 fun! Show_TitleString() "{{{2
226 " Vim 5 doesn't have printf.
229 let l:ts1=" " . l:ts1
231 let l:ts1=l:ts1 . ": " . expand('%t')
233 let l:ts1=l:ts1 . " (" . getcwd() . ")"
234 if has("clientserver")
235 let l:ts1=l:ts1 . " " . v:servername
240 " Toggle case-sensitivity.
241 fun! Invert_Case() "{{{2
245 " Can we resize this window?
246 fun! Can_Resize() "{{{2
249 if g:resizable == "0" || g:resizable == "1"
253 " Do we KNOW we can(not) resize?
254 if has("gui_running")
256 elseif $RESIZABLE == &term
258 elseif $RESIZABLE == "0"
261 " Assume we can. Allow overriding.
267 " Grow or shrink the window width.
268 fun! Resize_Columns(op, ...) "{{{2
278 " Vim 5 hardcodes the size of numbers column to 8.
279 if version >= "700" && has("linebreak")
280 let l:columns = &numberwidth
288 exe "let l:resize=" . &columns . a:op . l:columns
289 let l:resize = "se columns=" . l:resize
291 " HACK: Inside screen there is an extra line for the status bar. Vim
292 " manages the resize by sending an escape sequence to set the number of
293 " lines and number of columns in one action. To do this it will first query
294 " the number of lines and then set <same number of lines> by <new number of
295 " columns>. Because of the extra line for the status bar this results in
296 " the real terminal being shrunk by a line. We ask for the terminal to grow
297 " by a line so it ends up actually being the same.
298 if &term =~ '^screen'
299 let l:resize = l:resize . " lines=" . (&lines + 1)
305 " Grow or shrink the window height.
306 fun! Resize_Lines(op, lines) "{{{2
315 exe "let l:resize=" . &lines . a:op . a:lines
316 if &term =~ '^screen'
317 let l:resize = l:resize + 1
319 let l:resize = "se lines=" . l:resize
324 " Set extra columns depending on window status.
325 fun! Extra_Columns(extra, var, ...) "{{{2
326 " Vim 6 doesn't have winnr("$"). Determine which windows are open
327 " ourselves by using :windo to incremement a counter. As Vim 5
328 " doesn't have :windo we require Vim 6 for this.
336 " Remember which window we're in.
337 let l:winnr = winnr()
338 let l:num_windows = 0
339 windo let l:num_windows = l:num_windows + 1
340 " Switch back to the window we were in.
341 exe l:winnr . "wincmd w"
348 let l:condition = a:1
354 while l:n < l:num_windows
355 " If window w exists then getwinvar(w, "&modified") will be 0 or 1.
356 if getwinvar(l:i, "&modified") =~ '^\d'
360 exe "if getwinvar(" . l:i . ", '" . a:var . "') " . l:condition . " | let l:val = 1 | endif"
362 exe "let l:windows = '" . l:windows . ":" . l:i . "'"
368 let l:extra = "g:iainextracolumns" . a:extra
369 exe "let l:val = " . l:extra
370 exe "let " . l:extra . " = '" . l:windows . "'"
372 if l:windows == l:val
383 " Toggle number display.
384 fun! Number(resize) "{{{2
386 let &number = ! &number
388 " Ensure we keep track of any extra columns even if we aren't resizing.
389 " This prevents confusion when number is set at startup.
390 let l:extra = Extra_Columns("number", "&number")
393 call Resize_Columns(l:extra)
397 " Restore window size.
398 if has("autocmd") && ! has("gui_running")
399 au Display VimLeave * if exists("g:oldcols") | call Resize_Columns("-", (&columns - g:oldcols)) | endif
400 au Display VimLeave * if exists("g:oldlines") | call Resize_Lines("-", (&lines - g:oldlines)) | endif
405 au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif
406 au Mode BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
409 " Entering Make mode.
410 fun! MakeMode_map() "{{{2
419 fun! MakeMode_unmap() "{{{2
425 " Function to create mappings with either a hardcoded \ or <Leader>.
426 fun! Mapping(keysequence,mapping) "{{{2
428 exec "map \\" . a:keysequence . " " . a:mapping
430 exec "map <Leader>" . a:keysequence . " " . a:mapping
434 " Use - and = to create underlines.
435 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
436 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
438 " Change to ts=2 with \2.
439 call Mapping("2", ":se ts=2<CR>:<CR>")
440 " Change to ts=4 with \4.
441 call Mapping("4", ":se ts=4<CR>:<CR>")
442 " Change to ts=8 with \8.
443 call Mapping("8", ":se ts=8<CR>:<CR>")
444 " Change to ts=16 with \6.
445 call Mapping("6", ":se ts=16<CR>:<CR>")
446 " Change to ts=32 with \3.
447 call Mapping("3", ":se ts=32<CR>:<CR>")
448 " Toggle paste mode with \p.
449 call Mapping("p", ":se paste!<CR>:<CR>")
450 " Swap case-sensitivity with \c.
451 call Mapping("C", ":call Invert_Case()<CR>:<CR>")
452 " Change number mode with \n.
453 call Mapping("n", ":call Number(1)<CR>:<CR>")
454 " Expand or shrink window size with \> and \<.
455 call Mapping(">", ":call Resize_Columns('+')<CR>:<CR>")
456 call Mapping("<", ":call Resize_Columns('-')<CR>:<CR>")
457 " Clear search pattern with \/.
458 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
459 " Toggle alternate buffer name with \#.
460 call Mapping("#", ":call Cycle_Alt()<CR>:<CR>")
462 " Set graphical window title.
463 if has("win32") || has("win64")
464 " Windows taskbar entries are probably too small to show full titles.
467 se titlestring=%{Show_TitleString()}
470 " Vim tip 99: What's the highlighting group under the cursor?
471 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>")
473 fun! Uncluttered_Buffer() "{{{2
474 if exists("uncluttered_buffer")
475 if uncluttered_buffer == 1
494 if &ft == 'gitcommit'
501 fun! Startup_Resize() "{{{2
504 " Resize for numbers.
506 if version >= "700" && has("linebreak")
507 let l:columns = &numberwidth
517 let l:columns = l:columns + 2
522 if g:oldcols < (80 + l:columns)
523 call Resize_Columns("+", l:columns)
527 " Change status bar colour when various things happen.
528 " Flags: H/h: Cursor held/moved.
529 " F/f: Focus gained/lost.
530 " I/i: Insert mode entered/left.
531 fun! Highlight_StatusLine(flag) "{{{2
532 if ! has("statusline")
535 " Get current status.
538 " Change the status based on the flag. XXX: Does Vim let us to do flags?
541 let b:iainstatus = substitute(b:iainstatus, a:flag, a:flag, "")
544 let l:normalcolour = "darkblue"
545 let l:editingcolour = "darkmagenta"
546 let l:warningcolour = "darkred"
547 let l:readonlycolour = "red"
550 let l:colour = l:normalcolour
551 " Maybe override depending on status.
552 if b:iainstatus =~# "H"
553 if b:iainstatus =~# "I"
554 " Held in insert mode. Add extra highlight if we don't have focus.
555 if b:iainstatus =~# "f"
556 let l:colour = l:warningcolour
558 let l:colour = l:editingcolour
562 if b:iainstatus =~# "I"
563 " Regular insert mode.
564 let l:colour = l:editingcolour
568 " Override again if readonly.
569 if l:colour != l:normalcolour
570 if getbufvar("", "&ro")
571 let l:colour = l:readonlycolour
575 let l:termcolour = Iain_Colour(l:colour)
577 exec "highlight StatusLine gui=none term=none cterm=none guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
578 exec "highlight User1 gui=bold term=bold cterm=bold guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
581 fun! Iain_Colour(colour) "{{{2
583 if a:colour == "darkblue"
585 elseif a:colour == "darkmagenta"
587 elseif a:colour == "darkred"
589 elseif a:colour == "red"
593 if a:colour == "darkblue"
595 elseif a:colour == "darkmagenta"
597 elseif a:colour == "darkred"
599 elseif a:colour == "red"
608 au StatusLine VimEnter * call Highlight_StatusLine("")
610 " Show numbers by default.
611 au Display VimEnter * if ! Uncluttered_Buffer() | call Number(0) | endif
615 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
616 " Handle options only available in Vim 5.4 and above.
617 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
618 if version >= "504" "{{{1
621 " Reuse windows when using sbuffer.
624 " Do we have Unicode?
625 fun! Has_Unicode() "{{{2
626 if ! has('multi_byte')
634 if &tenc =~? '^u\(tf\|cs\)'
638 if ! strlen(&tenc) && &enc =~? '^u\(tf\|cs\)'
645 " Helper for status line.
646 " Show space, underscore or dollar sign depending on list mode.
647 fun! Show_List() "{{{2
669 " Helper for status line.
670 " Show c or C to denote case-sensitivity.
671 fun! Show_Case() "{{{2
679 " Helper for status line.
680 " Show the size of the tabstop.
681 fun! Show_Tabstop() "{{{2
685 " Helper for status line.
686 " Show p when paste mode is on.
687 fun! Show_Paste() "{{{2
695 " Helper for status line.
696 " Show v when virtualedit mode is block, insert or onemore.
697 " Show V when virtualedit mode is all.
698 fun! Show_VirtualEdit() "{{{2
699 if ! has("virtualedit")
712 " Helper for status line.
713 " Show U when persistent undo is on.
714 " Show u when persistent undo is off but an undofile exists.
715 fun! Show_Undo() "{{{2
716 if ! exists("&undofile")
722 elseif filereadable(undofile(expand("%")))
729 " Helper for status line.
730 " Show alternate buffer number and name.
731 fun! Show_Alt() "{{{2
732 let l:alt = bufnr("#")
733 if l:alt < 0 || l:alt == bufnr("") || ! b:iainalt
737 return " " . l:alt . ": " . expand("#:t")
740 " Helper for status line.
741 " Show scrollbind or cursorbind.
742 fun! Show_Bind() "{{{2
761 " Show the status line.
762 fun! Show_StatusLine() "{{{2
763 if ! has("statusline")
767 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()}\ '
768 let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%V%0*\ \|\ %P'
771 let l:hexformat='0\x%02B'
774 let l:sl1=l:sl1 . v:version . '\ %='
775 let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
777 let l:sl1=l:sl1 . '%='
780 exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
783 " Show the status line for the first time.
784 call Show_StatusLine()
787 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
788 " Handle options only available in Vim 6 and above.
789 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
790 if version >= "600" "{{{1
797 " Remember quickfix state.
802 " Set indenting by filetype.
805 " Less intrusive syntax highlighting.
811 if has("gui_running")
812 if has("win32") || has("win64")
813 exe "silent se guifont=DejaVu_Sans_Mono:h10:cANSI"
815 exe "silent se guifont=DejaVu\\ Sans\\ Mono\\ 10"
818 if has("gui_running") || &t_Co > 16
819 exe "silent colo iain"
822 " Ignore whitespace when diffing.
824 se diffopt=filler,iwhite
829 " Remember that we are opening the quickfix window.
830 au Mode BufWinEnter quickfix let g:quickfixing=1
831 au Mode BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
834 " Allow in-place editing of crontabs.
835 au Mode FileType crontab set backupcopy=yes
838 " Make * and # work the way you expect in visual mode.
839 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
840 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
842 " Set mark and update highlighting.
844 au Signs BufReadPost * call <SID>Highlight_Signs()
845 au Signs CursorHold * call <SID>Highlight_Signs()
848 " Helper to set buffer variable for a given sign.
849 fun! <SID>Prep_Sign(sign) "{{{2
850 if ! exists("b:sign" . a:sign) || ! g:marksigns
851 exe "let b:sign" . a:sign . "=0"
855 fun! <SID>Place_Sign(number, line, old, name) "{{{2
860 exe "sign unplace " . (g:firstsign + a:number) . " buffer=" . bufnr("")
861 " Don't place the sign if it would conflict with the last change sign.
862 exe "sign place " . (g:firstsign + a:number) . " line=" . a:line . " name=" . a:name . " buffer=" . bufnr("")
866 fun! <SID>Highlight_Signs(...) "{{{2
867 if ! has("signs") || ! g:marksigns || Uncluttered_Buffer()
871 let l:signs = g:iainsigns
874 while strlen(l:signs)
875 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+')
877 let l:name = substitute(l:sign, '[:.=-].*', "", "")
878 let l:var = tolower(l:name)
879 let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "")
880 let l:ascii = matchstr(l:sign, '^:.')
881 let l:mark = substitute(l:sign, '^\(:.\)*[.=-]', "", "")
883 let l:ascii = substitute(l:ascii, '^:', "", "")
887 let l:ascii = substitute(l:ascii, '"', '\\"', "")
889 call <SID>Prep_Sign(l:var)
890 exe "let " . l:var . " = <SID>Place_Sign(" . l:i . ", line(\"'" . l:ascii . "\"), b:sign" . l:var . ", \"Mark" . l:name . "\")"
893 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
898 fun! <SID>Cycle_Signs(resize) "{{{2
903 let g:marksigns = ! g:marksigns
905 " Retrofit arrays on to Vim 6.
906 if ! exists("g:iainsigns")
907 " Signs are defined in g:iainsigns. The syntax is as follows:
909 " Sign ::= Name (':' Mark)* Type Symbol
910 " Type ::= '=' | '-' | '.'
912 " Signs with Type '=' will be highlighted with the MarkSign group.
913 " Signs with Type '-' will be highlighted with the MarkLine group.
914 " Signs with Type '.' will be highlighted with the MarkDot group.
915 " Define the Mark where Symbol is not also the mark name, eg "']".
917 let g:iainsigns = "Dash:'=’ Dot:..• Quote:\"=” Caret:^.ʌ"
919 let g:iainsigns = "Dash=' Dot:..* Quote=\" Caret.^"
921 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"
925 " Signs to highlight marks.
926 " Syntax won't work properly in Vim 6.
927 let l:signs = g:iainsigns
929 while strlen(l:signs)
930 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+')
932 let l:sign = substitute(l:sign, ':.', "", "")
933 let l:sign = substitute(l:sign, '=', " texthl=MarkSign text=", "")
934 let l:sign = substitute(l:sign, '\.', " texthl=MarkDot text=", "")
935 let l:sign = substitute(l:sign, '-', " texthl=MarkLine linehl=MarkLine text=", "")
937 exe "sign define Mark" . l:sign
939 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
943 call Resize_Columns("+", 2)
945 call <SID>Highlight_Signs()
949 exe "sign unplace " . (g:firstsign + l:i)
953 let l:signs = g:iainsigns
955 while strlen(l:signs)
956 let l:sign = matchstr(l:signs, '^[A-Za-z]\+')
958 exe "sign undefine Mark" . l:sign
959 call <SID>Prep_Sign(tolower(l:sign))
960 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
964 call Resize_Columns("-", 2)
970 fun! Cycle_List() "{{{2
971 " Pretty UTF-8 listchars.
973 let basic='tab:»·,trail:…,extends:«,precedes:»'
976 let basic=basic . ',nbsp:•'
979 let basic='tab:\\_,trail:_,extends:<,precedes:>'
982 let basic=basic . ',nbsp:+'
986 let w:iainlist = w:iainlist + 1
992 elseif w:iainlist == 1
993 exec "setlocal lcs=" . basic
996 exec "setlocal lcs=" . basic . "," . eol
1000 call Resize_Columns(Extra_Columns("list", "iainlist", " == 2"), 1)
1001 call Extra_Whitespace_Match()
1004 " Cycle between hex and decimal display of toolbar stuff.
1005 fun! Cycle_HexStatusLine() "{{{2
1007 let b:iainhex = ! b:iainhex
1008 call Show_StatusLine()
1011 " Cycle verbose display of toolbar stuff.
1012 fun! Cycle_VerboseStatusLine() "{{{2
1014 let b:iainverbose = ! b:iainverbose
1015 call Show_StatusLine()
1018 " Toggle quickfix window.
1019 fun! Cycle_Quickfix() "{{{2
1020 if ! has("quickfix")
1023 if g:quickfixing == 1
1031 " Toggle showing alternate buffer information.
1032 fun! Cycle_Alt() "{{{2
1034 let b:iainalt = ! b:iainalt
1035 call Show_StatusLine()
1038 " To be overridden later if applicable.
1039 fun! Extra_Whitespace_Match() "{{{2
1043 " Swap hex/decimal statusline with \x.
1044 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
1045 " Change statusline verbosity with \v.
1046 call Mapping("V", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
1047 " Cycle list styles with \l.
1048 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
1049 " Toggle tags with \t.
1050 call Mapping("t", ":Tlist<CR>")
1051 " Change foldmethod with \f.
1052 call Mapping("f", ":se foldenable!<CR>:<CR>")
1053 " Toggle quickfix window with \q.
1054 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
1055 " Rerun filetype detection with \s. The s is for syntax, as this will be
1056 " updated as a side-effect.
1057 call Mapping("S", ":filetype detect<CR>:<CR>")
1058 " Toggle marks with \m.
1059 call Mapping("m", ":call <SID>Cycle_Signs(1)<CR>:<CR>")
1062 " Show signs by default.
1063 au Display VimEnter * call <SID>Cycle_Signs(0)
1067 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1068 " Handle options only available in Vim 7 and above.
1069 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1070 if version >= "700" "{{{1
1073 " Helper to show tab name.
1074 fun! <SID>TabName(label, gui) "{{{2
1075 let l:label = a:label
1077 let l:label = "No Name"
1079 let l:label = "[" . l:label . "]"
1082 let l:label = fnamemodify(l:label, ":t")
1083 if strlen(l:label) >= 18
1084 let l:label = l:label[0:17] . ".."
1090 " Find out if any buffer was modified.
1091 fun! <SID>TabModified(buflist) "{{{2
1093 while l:i < len(a:buflist)
1094 if getbufvar(a:buflist[l:i], "&modified") == 1
1103 fun! Show_TabLine() "{{{2
1104 let l:s = "%#TabLineFill#Tabs:"
1107 while l:i < tabpagenr("$")
1110 let l:buflist = tabpagebuflist(l:i)
1111 let l:winnr = tabpagewinnr(l:i)
1112 let l:n = tabpagewinnr(l:i, "$")
1113 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 0)
1114 let l:modified = <SID>TabModified(l:buflist)
1116 " Choose highlighting.
1117 if l:i == tabpagenr()
1118 let l:s .= "%#TabLineSel#[" . l:n . l:modified . " " . l:label . "]"
1120 let l:s .= "%#TabLine# " . l:n . l:modified . " " . l:label . " "
1125 let l:s .= "%#TabLine#%T"
1129 " Per tab label for the GUI.
1130 fun! Show_GUITabLine() "{{{2
1131 let l:buflist = tabpagebuflist(v:lnum)
1132 let l:winnr = tabpagewinnr(v:lnum)
1133 let l:s = tabpagewinnr(v:lnum, "$")
1134 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 1)
1135 let l:modified = <SID>TabModified(l:buflist)
1137 let l:s .= l:modified . " " . l:label
1141 " Toggle highlighting cursor line when focus changes.
1142 fun! <SID>ToggleCursorLine() "{{{2
1145 if b:iainstatus =~# "H" && b:iainstatus =~# "I"
1146 " We are held in insert mode.
1147 if b:iainstatus =~# "f"
1148 " And focus was lost.
1149 let b:iaincul = getbufvar("", "&cursorline")
1152 setlocal nocursorline
1157 " Handle searching in a BufExplorer window.
1158 fun! <SID>BufExplorer_Search(n) "{{{2
1160 let l:re = '^ *\d %'
1162 let l:re = "^ *" . a:n
1165 " Find matching line.
1166 let l:line = search(l:re, 'w')
1175 " Peek ahead to the next matching line.
1176 let l:next = search(l:re, 'w')
1178 " Select the buffer if the match is unambiguous.
1185 call cursor(l:line, 0)
1188 " Entering a BufExplorer window.
1189 fun! <SID>BufExplorer_Map() "{{{2
1190 for l:n in [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ]
1191 exec "nnoremap <buffer> <silent>" . l:n . " :call <SID>BufExplorer_Search(" . l:n . ")<CR>"
1196 se tabline=%!Show_TabLine()
1197 se guitablabel=%!Show_GUITabLine()
1201 au StatusLine CursorHoldI * call Highlight_StatusLine("H")
1202 au StatusLine CursorMovedI * call Highlight_StatusLine("h")
1203 au StatusLine FocusGained * call Highlight_StatusLine("F")
1204 au StatusLine FocusLost * call Highlight_StatusLine("f")
1205 au StatusLine InsertEnter * call Highlight_StatusLine("I")
1206 au StatusLine InsertLeave * call Highlight_StatusLine("i")
1209 au Display FocusGained,FocusLost * call <SID>ToggleCursorLine()
1213 au Signs InsertEnter * call <SID>Highlight_Signs()
1214 au Signs InsertLeave * call <SID>Highlight_Signs()
1217 au Mode BufEnter \[BufExplorer\] call <SID>BufExplorer_Map()
1220 " Limit the size of the popup menu when completing.
1221 if has("insert_expand")
1225 " Make diffs vertical by default.
1227 se diffopt+=vertical
1230 " Set size of numbers column.
1235 " Add "previous tab" mapping as gb.
1236 map gb :tabprevious<CR>:<CR>
1239 if has("gui_macvim")
1243 " Yet more GUI options. Add tabs.
1249 let g:p4EnableMenu=1
1250 let g:p4Presets='P4CONFIG'
1253 let g:bufExplorerShowRelativePath=1
1254 let g:bufExplorerSplitOutPathName=0
1257 let g:NERDSpaceDelims=1
1260 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1261 " Handle options only available in Vim 7.2 and above.
1262 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1263 if version >= "702" "{{{1
1265 " http://vim.wikia.com/wiki/Highlight_unwanted_spaces
1266 augroup WhitespaceMatch
1268 au Display BufWinEnter * call Extra_Whitespace_Match()
1269 au Display Syntax * call Extra_Whitespace_Match()
1270 au Display BufWinLeave * call clearmatches()
1273 fun! Extra_Whitespace_Match() "{{{2
1275 " $ <before end of line>
1276 " \@<! <unless preceded by>
1277 " \%# <cursor position, ie when typing>
1278 let l:pattern = '\s\+\%#\@<!$'
1279 " Don't match single space in first column of diff.
1280 if &ft =~# '^diff$\|git'
1281 " \@! <unless also matching>
1282 " \(^\s$\) <a single whitespace>
1283 let l:pattern = '\(^\s$\)\@!' . l:pattern
1286 let l:hl = 'ctermfg=red guifg=red'
1288 " Underline if we aren't using listchars.
1289 let l:hl = l:hl . ' cterm=underline gui=underline'
1291 highlight clear ExtraWhitespace
1292 exe "highlight ExtraWhitespace " . l:hl
1293 if exists('w:whitespace_match_number')
1295 call matchdelete(w:whitespace_match_number)
1298 call matchadd('ExtraWhitespace', l:pattern, 10, w:whitespace_match_number)
1300 let w:whitespace_match_number = matchadd('ExtraWhitespace', l:pattern)
1304 call Extra_Whitespace_Match()
1309 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1310 " Handle options only available in Vim 7.3 and above.
1311 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1312 if version >= "703" "{{{1
1315 " Toggle persistent undo with \u.
1316 call Mapping("u", ":call <SID>Cycle_Undo()<CR>:<CR>")
1317 " Remove persistent undo file with \U.
1318 call Mapping("U", ":call <SID>Clear_Undo()<CR>:<CR>")
1320 " Use a persistent undo file if it exists.
1321 fun! <SID>Check_Undo() "{{{2
1322 if filereadable(undofile(expand("%")))
1327 " Toggle persistent undo for this buffer.
1328 fun! <SID>Cycle_Undo() "{{{2
1329 if has("persistent_undo")
1330 let &undofile = ! &undofile
1334 " Remove the persistent undo file for this buffer.
1335 fun! <SID>Clear_Undo() "{{{2
1336 if ! has("persistent_undo")
1342 let l:f = expand("%")
1347 let l:u = undofile(l:f)
1352 if ! filereadable(l:u) || ! filewritable(l:u)
1359 " Toggle ColorColumn at cursor position.
1360 fun! <SID>Cycle_ColorColumn() "{{{2
1365 let l:cc = &colorcolumn
1366 let l:column = col(".")
1367 let l:re = ",*\\<" . l:column . "\\>"
1369 let l:cc = substitute(l:cc, l:re, "", "g")
1371 let l:cc = l:cc . "," . l:column
1373 let &colorcolumn = substitute(l:cc, "^,*", "", "")
1377 " Enable showing ColorColumn at cursor position with \CC.
1378 call Mapping("CC", ":call <SID>Cycle_ColorColumn()<CR>:<CR>")
1379 " Remove last shown ColorColumn with \Cc.
1380 call Mapping("Cc", ":let &colorcolumn=substitute(&colorcolumn, \",*[0-9]*$\", \"\", \"\")<CR>:<CR>")
1381 " Remove all ColorColumns with \Cx.
1382 call Mapping("Cx", ":se colorcolumn=<CR>:<CR>")
1385 " Use persistent undo if available.
1387 if has("persistent_undo")
1388 au File BufReadPost * call <SID>Check_Undo()
1391 if has("cursorbind")
1392 au Display WinEnter * if &diff | se cursorbind | endif
1397 " Resize after startup.
1398 if version >= "500" "{{{1
1400 au Display VimEnter * call Startup_Resize()