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 " Remember undo list for closed (but not wiped) buffers.
73 " Use ^B to search backward when completing.
75 " Use ^L to show matching completions but don't select one.
76 inoremap <C-l> <C-n><C-p>
82 " Select previous widnow.
84 noremap <C-w><C-^> <C-w>p
88 if (has("win32") || has("win64")) && version >= "504"
89 se rtp=~/.vim,$VIMRUNTIME
92 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
93 " Handle options only available in Vim 5 and above.
94 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
95 if version >= "500" "{{{1
98 " Tell Vim we use dark backgrounds in our terminals.
99 if ! has("gui_running")
103 " Allow mouse use in a terminal but only if it can work.
104 if has("xterm_clipboard")
108 " Update more quickly. For use with sign highlighting as polling for
109 " CursorMove makes redrawing slow.
114 " Enable tab-completion prompting for commands.
117 " Don't list object files when globbing files to load.
118 se wildignore+=*.o,*.obj
119 " So there's no need to assign them low priority.
120 se suffixes-=*.o,*.obj
123 " Save sessions in UNIX format with / as file separator. This is
129 " How often do we need to use ^A/^X on octals?
132 " Nuke any pre-existing autocommands.
149 " Save the current window dimensions so we can restore them when we quit.
150 if ! exists("g:oldcols")
151 let g:oldcols=&columns
153 if ! exists("g:oldlines")
154 let g:oldlines=&lines
157 " More GUI options. Add icon and tearoffs.
163 " Allow dynamic window resize even if we aren't in an xterm.
164 se t_WS=
\e[8;%p1%d;%p2%dt
166 " Highlight search results.
167 if has("extra_search")
171 " Syntax highlighting. New versions will use syn enable instead.
176 if has("user_commands")
183 " Forget the Ex mode mapping.
187 " Position the compview plugin window.
188 au Display BufEnter -SearchResults- set buftype=nowrite | set nonumber | wincmd J
192 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
193 " Handle options only available in Vim 5.2 and above.
194 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
195 if version >= "502" "{{{1
198 " Helper to initialise a variable.
199 fun! Prep_Var(var, value) "{{{2
203 exe "let " . a:var . "=" . a:value
206 " Set up our variables.
207 fun! Iain_Vars() "{{{2
208 call Prep_Var("w:iainlist", 0)
209 call Prep_Var("b:iainhex", 0)
210 call Prep_Var("b:iainverbose", 0)
211 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
212 call Prep_Var("b:iainstatus", "'Fih'")
213 call Prep_Var("g:iainextracolumnsnumber", "''")
214 call Prep_Var("g:iainextracolumnslist", "''")
215 call Prep_Var("b:iaincul", 0)
216 call Prep_Var("b:iainalt", 0)
218 call Prep_Var("g:marksigns", 0)
219 call Prep_Var("g:firstsign", 100)
221 call Prep_Var("g:resizable", "''")
224 " Show the window title.
225 fun! Show_TitleString() "{{{2
229 " Vim 5 doesn't have printf.
232 let l:ts1=" " . l:ts1
234 let l:ts1=l:ts1 . ": " . expand('%t')
236 let l:ts1=l:ts1 . " (" . getcwd() . ")"
237 if has("clientserver")
238 let l:ts1=l:ts1 . " " . v:servername
243 " Toggle case-sensitivity.
244 fun! Invert_Case() "{{{2
248 " Can we resize this window?
249 fun! Can_Resize() "{{{2
252 if g:resizable == "0" || g:resizable == "1"
256 " Do we KNOW we can(not) resize?
257 if has("gui_running")
259 elseif $RESIZABLE == &term
261 elseif $RESIZABLE == "0"
264 " Assume we can. Allow overriding.
270 " Grow or shrink the window width.
271 fun! Resize_Columns(op, ...) "{{{2
281 " Vim 5 hardcodes the size of numbers column to 8.
282 if version >= "700" && has("linebreak")
283 let l:columns = &numberwidth
291 exe "let l:resize=" . &columns . a:op . l:columns
292 let l:resize = "se columns=" . l:resize
294 " HACK: Inside screen there is an extra line for the status bar. Vim
295 " manages the resize by sending an escape sequence to set the number of
296 " lines and number of columns in one action. To do this it will first query
297 " the number of lines and then set <same number of lines> by <new number of
298 " columns>. Because of the extra line for the status bar this results in
299 " the real terminal being shrunk by a line. We ask for the terminal to grow
300 " by a line so it ends up actually being the same.
301 if &term =~ '^screen'
302 let l:resize = l:resize . " lines=" . (&lines + 1)
308 " Grow or shrink the window height.
309 fun! Resize_Lines(op, lines) "{{{2
318 exe "let l:resize=" . &lines . a:op . a:lines
319 if &term =~ '^screen'
320 let l:resize = l:resize + 1
322 let l:resize = "se lines=" . l:resize
327 " Set extra columns depending on window status.
328 fun! Extra_Columns(extra, var, ...) "{{{2
329 " Vim 6 doesn't have winnr("$"). Determine which windows are open
330 " ourselves by using :windo to incremement a counter. As Vim 5
331 " doesn't have :windo we require Vim 6 for this.
339 " Remember which window we're in.
340 let l:winnr = winnr()
341 let l:num_windows = 0
342 windo let l:num_windows = l:num_windows + 1
343 " Switch back to the window we were in.
344 exe l:winnr . "wincmd w"
351 let l:condition = a:1
357 while l:n < l:num_windows
358 " If window w exists then getwinvar(w, "&modified") will be 0 or 1.
359 if getwinvar(l:i, "&modified") =~ '^\d'
363 exe "if getwinvar(" . l:i . ", '" . a:var . "') " . l:condition . " | let l:val = 1 | endif"
365 exe "let l:windows = '" . l:windows . ":" . l:i . "'"
371 let l:extra = "g:iainextracolumns" . a:extra
372 exe "let l:val = " . l:extra
373 exe "let " . l:extra . " = '" . l:windows . "'"
375 if l:windows == l:val
386 " Toggle number display.
387 fun! Number(resize) "{{{2
389 let &number = ! &number
391 " Ensure we keep track of any extra columns even if we aren't resizing.
392 " This prevents confusion when number is set at startup.
393 let l:extra = Extra_Columns("number", "&number")
396 call Resize_Columns(l:extra)
400 " Restore window size.
401 if has("autocmd") && ! has("gui_running")
402 au Display VimLeave * if exists("g:oldcols") | call Resize_Columns("-", (&columns - g:oldcols)) | endif
403 au Display VimLeave * if exists("g:oldlines") | call Resize_Lines("-", (&lines - g:oldlines)) | endif
408 au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif
409 au Mode BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
412 " Entering Make mode.
413 fun! MakeMode_map() "{{{2
422 fun! MakeMode_unmap() "{{{2
428 " Function to create mappings with either a hardcoded \ or <Leader>.
429 fun! Mapping(keysequence,mapping) "{{{2
431 exec "map \\" . a:keysequence . " " . a:mapping
433 exec "map <Leader>" . a:keysequence . " " . a:mapping
437 " Use - and = to create underlines.
438 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
439 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
441 " Change to ts=2 with \2.
442 call Mapping("2", ":se ts=2<CR>:<CR>")
443 " Change to ts=4 with \4.
444 call Mapping("4", ":se ts=4<CR>:<CR>")
445 " Change to ts=8 with \8.
446 call Mapping("8", ":se ts=8<CR>:<CR>")
447 " Change to ts=16 with \6.
448 call Mapping("6", ":se ts=16<CR>:<CR>")
449 " Change to ts=32 with \3.
450 call Mapping("3", ":se ts=32<CR>:<CR>")
451 " Toggle paste mode with \p.
452 call Mapping("p", ":se paste!<CR>:<CR>")
453 " Swap case-sensitivity with \c.
454 call Mapping("C", ":call Invert_Case()<CR>:<CR>")
455 " Change number mode with \n.
456 call Mapping("n", ":call Number(1)<CR>:<CR>")
457 " Expand or shrink window size with \> and \<.
458 call Mapping(">", ":call Resize_Columns('+')<CR>:<CR>")
459 call Mapping("<", ":call Resize_Columns('-')<CR>:<CR>")
460 " Clear search pattern with \/.
461 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
462 " Toggle alternate buffer name with \#.
463 call Mapping("#", ":call Cycle_Alt()<CR>:<CR>")
465 " Set graphical window title.
466 if has("win32") || has("win64")
467 " Windows taskbar entries are probably too small to show full titles.
470 se titlestring=%{Show_TitleString()}
473 " Vim tip 99: What's the highlighting group under the cursor?
474 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>")
476 fun! Uncluttered_Buffer() "{{{2
477 if exists("uncluttered_buffer")
478 if uncluttered_buffer == 1
497 if &ft == 'gitcommit'
504 fun! Startup_Resize() "{{{2
507 " Resize for numbers.
509 if version >= "700" && has("linebreak")
510 let l:columns = &numberwidth
520 let l:columns = l:columns + 2
525 if g:oldcols < (80 + l:columns)
526 call Resize_Columns("+", l:columns)
530 " Change status bar colour when various things happen.
531 " Flags: H/h: Cursor held/moved.
532 " F/f: Focus gained/lost.
533 " I/i: Insert mode entered/left.
534 fun! Highlight_StatusLine(flag) "{{{2
535 if ! has("statusline")
538 " Get current status.
541 " Change the status based on the flag. XXX: Does Vim let us to do flags?
544 let b:iainstatus = substitute(b:iainstatus, a:flag, a:flag, "")
547 let l:normalcolour = "darkblue"
548 let l:editingcolour = "darkmagenta"
549 let l:warningcolour = "darkred"
550 let l:readonlycolour = "red"
553 let l:colour = l:normalcolour
554 " Maybe override depending on status.
555 if b:iainstatus =~# "H"
556 if b:iainstatus =~# "I"
557 " Held in insert mode. Add extra highlight if we don't have focus.
558 if b:iainstatus =~# "f"
559 let l:colour = l:warningcolour
561 let l:colour = l:editingcolour
565 if b:iainstatus =~# "I"
566 " Regular insert mode.
567 let l:colour = l:editingcolour
571 " Override again if readonly.
572 if l:colour != l:normalcolour
573 if getbufvar("", "&ro")
574 let l:colour = l:readonlycolour
578 let l:termcolour = Iain_Colour(l:colour)
580 exec "highlight StatusLine gui=none term=none cterm=none guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
581 exec "highlight User1 gui=bold term=bold cterm=bold guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
584 fun! Iain_Colour(colour) "{{{2
586 if a:colour == "darkblue"
588 elseif a:colour == "darkmagenta"
590 elseif a:colour == "darkred"
592 elseif a:colour == "red"
596 if a:colour == "darkblue"
598 elseif a:colour == "darkmagenta"
600 elseif a:colour == "darkred"
602 elseif a:colour == "red"
611 au StatusLine VimEnter * call Highlight_StatusLine("")
613 " Show numbers by default.
614 au Display VimEnter * if ! Uncluttered_Buffer() | call Number(0) | endif
618 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
619 " Handle options only available in Vim 5.4 and above.
620 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
621 if version >= "504" "{{{1
624 " Reuse windows when using sbuffer.
627 " Allow persistent variable saving for localvimrc.
630 " Do we have Unicode?
631 fun! Has_Unicode() "{{{2
632 if ! has('multi_byte')
640 if &tenc =~? '^u\(tf\|cs\)'
644 if ! strlen(&tenc) && &enc =~? '^u\(tf\|cs\)'
651 " Helper for status line.
652 " Show space, underscore or dollar sign depending on list mode.
653 fun! Show_List() "{{{2
675 " Helper for status line.
676 " Show c or C to denote case-sensitivity.
677 fun! Show_Case() "{{{2
685 " Helper for status line.
686 " Show the size of the tabstop.
687 fun! Show_Tabstop() "{{{2
691 " Helper for status line.
692 " Show p when paste mode is on.
693 fun! Show_Paste() "{{{2
701 " Helper for status line.
702 " Show v when virtualedit mode is block, insert or onemore.
703 " Show V when virtualedit mode is all.
704 fun! Show_VirtualEdit() "{{{2
705 if ! has("virtualedit")
718 " Helper for status line.
719 " Show U when persistent undo is on.
720 " Show u when persistent undo is off but an undofile exists.
721 fun! Show_Undo() "{{{2
722 if ! exists("&undofile")
728 elseif filereadable(undofile(expand("%")))
735 " Helper for status line.
736 " Show alternate buffer number and name.
737 fun! Show_Alt() "{{{2
738 let l:alt = bufnr("#")
739 if l:alt < 0 || l:alt == bufnr("") || ! b:iainalt
743 return " " . l:alt . ": " . expand("#:t")
746 " Helper for status line.
747 " Show scrollbind or cursorbind.
748 fun! Show_Bind() "{{{2
767 " Show the status line.
768 fun! Show_StatusLine() "{{{2
769 if ! has("statusline")
773 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()}\ '
774 let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%V%0*\ \|\ %P'
777 let l:hexformat='0\x%02B'
780 let l:sl1=l:sl1 . v:version . '\ %='
781 let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
783 let l:sl1=l:sl1 . '%='
786 exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
789 " Show the status line for the first time.
790 call Show_StatusLine()
793 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
794 " Handle options only available in Vim 6 and above.
795 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
796 if version >= "600" "{{{1
803 " Remember quickfix state.
808 " Set indenting by filetype.
811 " Less intrusive syntax highlighting.
817 if has("gui_running")
818 if has("win32") || has("win64")
819 exe "silent se guifont=DejaVu_Sans_Mono:h10:cANSI"
821 exe "silent se guifont=DejaVu\\ Sans\\ Mono\\ 10"
824 if has("gui_running") || &t_Co > 16
825 exe "silent colo iain"
828 " Ignore whitespace when diffing.
830 se diffopt=filler,iwhite
835 " Remember that we are opening the quickfix window.
836 au Mode BufWinEnter quickfix let g:quickfixing=1
837 au Mode BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
840 " Allow in-place editing of crontabs.
841 au Mode FileType crontab set backupcopy=yes
844 " Make * and # work the way you expect in visual mode.
845 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
846 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
848 " Set mark and update highlighting.
850 au Signs BufReadPost * call <SID>Highlight_Signs()
851 au Signs CursorHold * call <SID>Highlight_Signs()
854 " Helper to set buffer variable for a given sign.
855 fun! <SID>Prep_Sign(sign) "{{{2
856 if ! exists("b:sign" . a:sign) || ! g:marksigns
857 exe "let b:sign" . a:sign . "=0"
861 fun! <SID>Place_Sign(number, line, old, name) "{{{2
866 exe "sign unplace " . (g:firstsign + a:number) . " buffer=" . bufnr("")
867 " Don't place the sign if it would conflict with the last change sign.
868 exe "sign place " . (g:firstsign + a:number) . " line=" . a:line . " name=" . a:name . " buffer=" . bufnr("")
872 fun! <SID>Highlight_Signs(...) "{{{2
873 if ! has("signs") || ! g:marksigns || Uncluttered_Buffer()
877 let l:signs = g:iainsigns
880 while strlen(l:signs)
881 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+')
883 let l:name = substitute(l:sign, '[:.=-].*', "", "")
884 let l:var = tolower(l:name)
885 let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "")
886 let l:ascii = matchstr(l:sign, '^:.')
887 let l:mark = substitute(l:sign, '^\(:.\)*[.=-]', "", "")
889 let l:ascii = substitute(l:ascii, '^:', "", "")
893 let l:ascii = substitute(l:ascii, '"', '\\"', "")
895 call <SID>Prep_Sign(l:var)
896 exe "let " . l:var . " = <SID>Place_Sign(" . l:i . ", line(\"'" . l:ascii . "\"), b:sign" . l:var . ", \"Mark" . l:name . "\")"
899 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
904 fun! <SID>Cycle_Signs(resize) "{{{2
909 let g:marksigns = ! g:marksigns
911 " Retrofit arrays on to Vim 6.
912 if ! exists("g:iainsigns")
913 " Signs are defined in g:iainsigns. The syntax is as follows:
915 " Sign ::= Name (':' Mark)* Type Symbol
916 " Type ::= '=' | '-' | '.'
918 " Signs with Type '=' will be highlighted with the MarkSign group.
919 " Signs with Type '-' will be highlighted with the MarkLine group.
920 " Signs with Type '.' will be highlighted with the MarkDot group.
921 " Define the Mark where Symbol is not also the mark name, eg "']".
923 let g:iainsigns = "Dash:'=’ Dot:..• Quote:\"=” Caret:^.ʌ"
925 let g:iainsigns = "Dash=' Dot:..* Quote=\" Caret.^"
927 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"
931 " Signs to highlight marks.
932 " Syntax won't work properly in Vim 6.
933 let l:signs = g:iainsigns
935 while strlen(l:signs)
936 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+')
938 let l:sign = substitute(l:sign, ':.', "", "")
939 let l:sign = substitute(l:sign, '=', " texthl=MarkSign text=", "")
940 let l:sign = substitute(l:sign, '\.', " texthl=MarkDot text=", "")
941 let l:sign = substitute(l:sign, '-', " texthl=MarkLine linehl=MarkLine text=", "")
943 exe "sign define Mark" . l:sign
945 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
949 call Resize_Columns("+", 2)
951 call <SID>Highlight_Signs()
955 exe "sign unplace " . (g:firstsign + l:i)
959 let l:signs = g:iainsigns
961 while strlen(l:signs)
962 let l:sign = matchstr(l:signs, '^[A-Za-z]\+')
964 exe "sign undefine Mark" . l:sign
965 call <SID>Prep_Sign(tolower(l:sign))
966 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
970 call Resize_Columns("-", 2)
976 fun! Cycle_List() "{{{2
977 " Pretty UTF-8 listchars.
979 let basic='tab:»·,trail:…,extends:«,precedes:»'
982 let basic=basic . ',nbsp:•'
985 let basic='tab:\\_,trail:_,extends:<,precedes:>'
988 let basic=basic . ',nbsp:+'
992 let w:iainlist = w:iainlist + 1
998 elseif w:iainlist == 1
999 exec "setlocal lcs=" . basic
1002 exec "setlocal lcs=" . basic . "," . eol
1006 call Resize_Columns(Extra_Columns("list", "iainlist", " == 2"), 1)
1007 call Extra_Whitespace_Match()
1010 " Cycle between hex and decimal display of toolbar stuff.
1011 fun! Cycle_HexStatusLine() "{{{2
1013 let b:iainhex = ! b:iainhex
1014 call Show_StatusLine()
1017 " Cycle verbose display of toolbar stuff.
1018 fun! Cycle_VerboseStatusLine() "{{{2
1020 let b:iainverbose = ! b:iainverbose
1021 call Show_StatusLine()
1024 " Toggle quickfix window.
1025 fun! Cycle_Quickfix() "{{{2
1026 if ! has("quickfix")
1029 if g:quickfixing == 1
1037 " Toggle showing alternate buffer information.
1038 fun! Cycle_Alt() "{{{2
1040 let b:iainalt = ! b:iainalt
1041 call Show_StatusLine()
1044 " To be overridden later if applicable.
1045 fun! Extra_Whitespace_Match() "{{{2
1049 " Swap hex/decimal statusline with \x.
1050 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
1051 " Change statusline verbosity with \v.
1052 call Mapping("V", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
1053 " Cycle list styles with \l.
1054 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
1055 " Toggle tags with \t.
1056 call Mapping("t", ":Tlist<CR>")
1057 " Change foldmethod with \f.
1058 call Mapping("f", ":se foldenable!<CR>:<CR>")
1059 " Toggle quickfix window with \q.
1060 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
1061 " Rerun filetype detection with \s. The s is for syntax, as this will be
1062 " updated as a side-effect.
1063 call Mapping("S", ":filetype detect<CR>:<CR>")
1064 " Toggle marks with \m.
1065 call Mapping("m", ":call <SID>Cycle_Signs(1)<CR>:<CR>")
1068 " Show signs by default.
1069 au Display VimEnter * call <SID>Cycle_Signs(0)
1074 nmap <A-u> <Plug>MoveLineHalfPageUp
1075 nmap <A-d> <Plug>MoveLineHalfPageDown
1076 vmap <A-u> <Plug>MoveBlockHalfPageUp
1077 vmap <A-d> <Plug>MoveBlockHalfPageDown
1079 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1080 " Handle options only available in Vim 7 and above.
1081 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1082 if version >= "700" "{{{1
1085 " Helper to show tab name.
1086 fun! <SID>TabName(label, gui) "{{{2
1087 let l:label = a:label
1089 let l:label = "No Name"
1091 let l:label = "[" . l:label . "]"
1094 let l:label = fnamemodify(l:label, ":t")
1095 if strlen(l:label) >= 18
1096 let l:label = l:label[0:17] . ".."
1102 " Find out if any buffer was modified.
1103 fun! <SID>TabModified(buflist) "{{{2
1105 while l:i < len(a:buflist)
1106 if getbufvar(a:buflist[l:i], "&modified") == 1
1115 fun! Show_TabLine() "{{{2
1116 let l:s = "%#TabLineFill#Tabs:"
1119 while l:i < tabpagenr("$")
1122 let l:buflist = tabpagebuflist(l:i)
1123 let l:winnr = tabpagewinnr(l:i)
1124 let l:n = tabpagewinnr(l:i, "$")
1125 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 0)
1126 let l:modified = <SID>TabModified(l:buflist)
1128 " Choose highlighting.
1129 if l:i == tabpagenr()
1130 let l:s .= "%#TabLineSel#[" . l:n . l:modified . " " . l:label . "]"
1132 let l:s .= "%#TabLine# " . l:n . l:modified . " " . l:label . " "
1137 let l:s .= "%#TabLine#%T"
1141 " Per tab label for the GUI.
1142 fun! Show_GUITabLine() "{{{2
1143 let l:buflist = tabpagebuflist(v:lnum)
1144 let l:winnr = tabpagewinnr(v:lnum)
1145 let l:s = tabpagewinnr(v:lnum, "$")
1146 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 1)
1147 let l:modified = <SID>TabModified(l:buflist)
1149 let l:s .= l:modified . " " . l:label
1153 " Toggle highlighting cursor line when focus changes.
1154 fun! <SID>ToggleCursorLine() "{{{2
1157 if b:iainstatus =~# "H" && b:iainstatus =~# "I"
1158 " We are held in insert mode.
1159 if b:iainstatus =~# "f"
1160 " And focus was lost.
1161 let b:iaincul = getbufvar("", "&cursorline")
1164 setlocal nocursorline
1169 " Handle searching in a BufExplorer window.
1170 fun! <SID>BufExplorer_Search(n) "{{{2
1172 let l:re = '^ *\d %'
1174 let l:re = "^ *" . a:n
1177 " Find matching line.
1178 let l:line = search(l:re, 'w')
1187 " Peek ahead to the next matching line.
1188 let l:next = search(l:re, 'w')
1190 " Select the buffer if the match is unambiguous.
1197 call cursor(l:line, 0)
1200 " Entering a BufExplorer window.
1201 fun! <SID>BufExplorer_Map() "{{{2
1202 for l:n in [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ]
1203 exec "nnoremap <buffer> <silent>" . l:n . " :call <SID>BufExplorer_Search(" . l:n . ")<CR>"
1208 se tabline=%!Show_TabLine()
1209 se guitablabel=%!Show_GUITabLine()
1213 au StatusLine CursorHoldI * call Highlight_StatusLine("H")
1214 au StatusLine CursorMovedI * call Highlight_StatusLine("h")
1215 au StatusLine FocusGained * call Highlight_StatusLine("F")
1216 au StatusLine FocusLost * call Highlight_StatusLine("f")
1217 au StatusLine InsertEnter * call Highlight_StatusLine("I")
1218 au StatusLine InsertLeave * call Highlight_StatusLine("i")
1221 au Display FocusGained,FocusLost * call <SID>ToggleCursorLine()
1225 au Signs InsertEnter * call <SID>Highlight_Signs()
1226 au Signs InsertLeave * call <SID>Highlight_Signs()
1229 au Mode BufEnter \[BufExplorer\] call <SID>BufExplorer_Map()
1232 " Limit the size of the popup menu when completing.
1233 if has("insert_expand")
1237 " Make diffs vertical by default.
1239 se diffopt+=vertical
1242 " Set size of numbers column.
1247 " Add "previous tab" mapping as gb.
1248 map gb :tabprevious<CR>:<CR>
1251 if has("gui_macvim")
1255 " Yet more GUI options. Add tabs.
1261 let g:p4EnableMenu=1
1262 let g:p4Presets='P4CONFIG'
1265 let g:bufExplorerShowRelativePath=1
1266 let g:bufExplorerSplitOutPathName=0
1269 let g:NERDSpaceDelims=1
1273 let g:localvimrc_persistent=1
1275 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1276 " Handle options only available in Vim 7.2 and above.
1277 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1278 if version >= "702" "{{{1
1280 " http://vim.wikia.com/wiki/Highlight_unwanted_spaces
1281 augroup WhitespaceMatch
1283 au Display BufWinEnter * call Extra_Whitespace_Match()
1284 au Display Syntax * call Extra_Whitespace_Match()
1285 au Display BufWinLeave * call clearmatches()
1288 fun! Extra_Whitespace_Match() "{{{2
1290 " $ <before end of line>
1291 " \@<! <unless preceded by>
1292 " \%# <cursor position, ie when typing>
1293 let l:pattern = '\s\+\%#\@<!$'
1294 " Don't match single space in first column of diff.
1295 if &ft =~# '^diff$\|git'
1296 " \@! <unless also matching>
1297 " \(^\s$\) <a single whitespace>
1298 let l:pattern = '\(^\s$\)\@!' . l:pattern
1301 let l:hl = 'ctermfg=red guifg=red'
1303 " Underline if we aren't using listchars.
1304 let l:hl = l:hl . ' cterm=underline gui=underline'
1306 highlight clear ExtraWhitespace
1307 exe "highlight ExtraWhitespace " . l:hl
1308 if exists('w:whitespace_match_number')
1310 call matchdelete(w:whitespace_match_number)
1313 call matchadd('ExtraWhitespace', l:pattern, 10, w:whitespace_match_number)
1315 let w:whitespace_match_number = matchadd('ExtraWhitespace', l:pattern)
1319 call Extra_Whitespace_Match()
1324 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1325 " Handle options only available in Vim 7.3 and above.
1326 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1327 if version >= "703" "{{{1
1330 " Toggle persistent undo with \u.
1331 call Mapping("u", ":call <SID>Cycle_Undo()<CR>:<CR>")
1332 " Remove persistent undo file with \U.
1333 call Mapping("U", ":call <SID>Clear_Undo()<CR>:<CR>")
1335 " Use a persistent undo file if it exists.
1336 fun! <SID>Check_Undo() "{{{2
1337 if filereadable(undofile(expand("%")))
1342 " Toggle persistent undo for this buffer.
1343 fun! <SID>Cycle_Undo() "{{{2
1344 if has("persistent_undo")
1345 let &undofile = ! &undofile
1349 " Remove the persistent undo file for this buffer.
1350 fun! <SID>Clear_Undo() "{{{2
1351 if ! has("persistent_undo")
1357 let l:f = expand("%")
1362 let l:u = undofile(l:f)
1367 if ! filereadable(l:u) || ! filewritable(l:u)
1374 " Toggle ColorColumn at cursor position.
1375 fun! <SID>Cycle_ColorColumn() "{{{2
1380 let l:cc = &colorcolumn
1381 let l:column = col(".")
1382 let l:re = ",*\\<" . l:column . "\\>"
1384 let l:cc = substitute(l:cc, l:re, "", "g")
1386 let l:cc = l:cc . "," . l:column
1388 let &colorcolumn = substitute(l:cc, "^,*", "", "")
1392 " Enable showing ColorColumn at cursor position with \CC.
1393 call Mapping("CC", ":call <SID>Cycle_ColorColumn()<CR>:<CR>")
1394 " Remove last shown ColorColumn with \Cc.
1395 call Mapping("Cc", ":let &colorcolumn=substitute(&colorcolumn, \",*[0-9]*$\", \"\", \"\")<CR>:<CR>")
1396 " Remove all ColorColumns with \Cx.
1397 call Mapping("Cx", ":se colorcolumn=<CR>:<CR>")
1400 " Use persistent undo if available.
1402 if has("persistent_undo")
1403 au File BufReadPost * call <SID>Check_Undo()
1406 if has("cursorbind")
1407 au Display WinEnter * if &diff | se cursorbind | endif
1412 " Resize after startup.
1413 if version >= "500" "{{{1
1415 au Display VimEnter * call Startup_Resize()