1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 " Multi-version vimrc compatible with version 4 and above. vim6: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.
83 nnoremap <C-w>^ <C-w>p
84 nnoremap <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:iainalt", 0)
217 call Prep_Var("g:marksigns", 0)
218 call Prep_Var("g:firstsign", 100)
220 call Prep_Var("g:resizable", "''")
223 " Show the window title.
224 fun! Show_TitleString() "{{{2
228 " Vim 5 doesn't have printf.
231 let l:ts1=" " . l:ts1
233 let l:ts1=l:ts1 . ": " . expand('%t')
235 let l:ts1=l:ts1 . " (" . getcwd() . ")"
236 if has("clientserver")
237 let l:ts1=l:ts1 . " " . v:servername
242 " Toggle case-sensitivity.
243 fun! Invert_Case() "{{{2
247 " Can we resize this window?
248 fun! Can_Resize() "{{{2
251 if g:resizable == "0" || g:resizable == "1"
255 " Do we KNOW we can(not) resize?
256 if has("gui_running")
258 elseif $RESIZABLE == &term
260 elseif $RESIZABLE == "0"
263 " Assume we can. Allow overriding.
269 " Grow or shrink the window width.
270 fun! Resize_Columns(op, ...) "{{{2
280 " Vim 5 hardcodes the size of numbers column to 8.
281 if version >= "700" && has("linebreak")
282 let l:columns = &numberwidth
290 exe "let l:resize=" . &columns . a:op . l:columns
291 let l:resize = "se columns=" . l:resize
293 " HACK: Inside screen there is an extra line for the status bar. Vim
294 " manages the resize by sending an escape sequence to set the number of
295 " lines and number of columns in one action. To do this it will first query
296 " the number of lines and then set <same number of lines> by <new number of
297 " columns>. Because of the extra line for the status bar this results in
298 " the real terminal being shrunk by a line. We ask for the terminal to grow
299 " by a line so it ends up actually being the same.
300 if &term =~ '^screen'
301 let l:resize = l:resize . " lines=" . (&lines + 1)
307 " Grow or shrink the window height.
308 fun! Resize_Lines(op, lines) "{{{2
317 exe "let l:resize=" . &lines . a:op . a:lines
318 if &term =~ '^screen'
319 let l:resize = l:resize + 1
321 let l:resize = "se lines=" . l:resize
326 " Set extra columns depending on window status.
327 fun! Extra_Columns(extra, var, ...) "{{{2
328 " Vim 6 doesn't have winnr("$"). Determine which windows are open
329 " ourselves by using :windo to incremement a counter. As Vim 5
330 " doesn't have :windo we require Vim 6 for this.
338 " Remember which window we're in.
339 let l:winnr = winnr()
340 let l:num_windows = 0
341 windo let l:num_windows = l:num_windows + 1
342 " Switch back to the window we were in.
343 exe l:winnr . "wincmd w"
350 let l:condition = a:1
356 while l:n < l:num_windows
357 " If window w exists then getwinvar(w, "&modified") will be 0 or 1.
358 if getwinvar(l:i, "&modified") =~ '^\d'
362 exe "if getwinvar(" . l:i . ", '" . a:var . "') " . l:condition . " | let l:val = 1 | endif"
364 exe "let l:windows = '" . l:windows . ":" . l:i . "'"
370 let l:extra = "g:iainextracolumns" . a:extra
371 exe "let l:val = " . l:extra
372 exe "let " . l:extra . " = '" . l:windows . "'"
374 if l:windows == l:val
385 " Toggle number display.
386 fun! Number(resize) "{{{2
388 let &number = ! &number
390 " Ensure we keep track of any extra columns even if we aren't resizing.
391 " This prevents confusion when number is set at startup.
392 let l:extra = Extra_Columns("number", "&number")
395 call Resize_Columns(l:extra)
399 " Restore window size.
400 if has("autocmd") && ! has("gui_running")
401 au Display VimLeave * if exists("g:oldcols") | call Resize_Columns("-", (&columns - g:oldcols)) | endif
402 au Display VimLeave * if exists("g:oldlines") | call Resize_Lines("-", (&lines - g:oldlines)) | endif
407 au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif
408 au Mode BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
411 " Entering Make mode.
412 fun! MakeMode_map() "{{{2
421 fun! MakeMode_unmap() "{{{2
427 " Function to create mappings with either a hardcoded \ or <Leader>.
428 fun! Mapping(keysequence, mapping, ...) "{{{2
430 let l:args = "\\" . a:keysequence . " " . a:mapping . ":<CR>"
432 let l:args = "<silent> <Leader>" . a:keysequence . " " . a:mapping
438 " Specific mapping(s).
441 exec "let l:map = a:" . l:i . " . \"map\""
442 exec l:map . " " . l:args
448 " Use - and = to create underlines.
449 call Mapping("-", "yyp:s/./-/g<CR>:let @/=''<CR>")
450 call Mapping("=", "yyp:s/./=/g<CR>:let @/=''<CR>")
452 fun! Tab_Width(width) "{{{2
453 exec "set sw=" . a:width
454 exec "set ts=" . a:width
457 " Set 2-column tabs with \2.
458 call Mapping("2", ":call Tab_Width(2)<CR>")
459 " Set 4-column tabs with \4.
460 call Mapping("4", ":call Tab_Width(4)<CR>")
461 " Set 8-column tabs with \8.
462 call Mapping("8", ":call Tab_Width(8)<CR>")
463 " Set 16-column tabs with \6.
464 call Mapping("6", ":call Tab_Width(16)<CR>")
465 " Set 32-column tabs with \3.
466 call Mapping("3", ":call Tab_Width(32)<CR>")
467 " Toggle paste mode with \p.
468 call Mapping("p", ":se paste!<CR>")
469 " Swap case-sensitivity with \c.
470 call Mapping("C", ":call Invert_Case()<CR>")
471 " Change number mode with \n.
472 call Mapping("n", ":call Number(1)<CR>")
473 " Expand or shrink window size with \> and \<.
474 call Mapping(">", ":call Resize_Columns('+')<CR>")
475 call Mapping("<", ":call Resize_Columns('-')<CR>")
476 " Clear search pattern with \/.
477 call Mapping("/", ":let @/=\"\"<CR>")
478 " Toggle alternate buffer name with \#.
479 call Mapping("#", ":call Cycle_Alt()<CR>")
481 " Set graphical window title.
482 if has("win32") || has("win64")
483 " Windows taskbar entries are probably too small to show full titles.
486 se titlestring=%{Show_TitleString()}
489 " Vim tip 99: What's the highlighting group under the cursor?
490 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>")
492 fun! Uncluttered_Buffer() "{{{2
493 if exists("uncluttered_buffer")
494 if uncluttered_buffer == 1
513 if &ft == 'gitcommit'
520 fun! Startup_Resize() "{{{2
523 " Resize for numbers.
525 if version >= "700" && has("linebreak")
526 let l:columns = &numberwidth
536 let l:columns = l:columns + 2
541 if g:oldcols < (80 + l:columns)
542 call Resize_Columns("+", l:columns)
546 " Change status bar colour when various things happen.
547 " Flags: H/h: Cursor held/moved.
548 " F/f: Focus gained/lost.
549 " I/i: Insert mode entered/left.
550 fun! Highlight_StatusLine(flag) "{{{2
551 if ! has("statusline")
554 " Get current status.
557 " Change the status based on the flag. XXX: Does Vim let us to do flags?
560 let b:iainstatus = substitute(b:iainstatus, a:flag, a:flag, "")
563 let l:normalcolour = "darkblue"
564 let l:editingcolour = "darkmagenta"
565 let l:replacecolour = "purple"
566 let l:warningcolour = "darkred"
567 let l:readonlycolour = "red"
569 if b:iainstatus =~# "I"
570 if v:insertmode == "r"
571 let l:editingcolour = l:replacecolour
576 let l:colour = l:normalcolour
577 " Maybe override depending on status.
578 if b:iainstatus =~# "H"
579 if b:iainstatus =~# "I"
580 " Held in insert mode. Add extra highlight if we don't have focus.
581 if b:iainstatus =~# "f"
582 let l:colour = l:warningcolour
584 let l:colour = l:editingcolour
588 if b:iainstatus =~# "I"
589 " Regular insert mode.
590 let l:colour = l:editingcolour
594 " Override again if readonly.
595 if l:colour != l:normalcolour
596 if getbufvar("", "&ro")
597 let l:colour = l:readonlycolour
601 let l:termcolour = Iain_Colour(l:colour)
603 exec "highlight StatusLine gui=none term=none cterm=none guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
604 exec "highlight User1 gui=bold term=bold cterm=bold guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour
607 fun! Iain_Colour(colour) "{{{2
609 if a:colour == "darkblue"
611 elseif a:colour == "darkmagenta"
613 elseif a:colour == "purple"
615 elseif a:colour == "darkred"
617 elseif a:colour == "red"
621 if a:colour == "darkblue"
623 elseif a:colour == "darkmagenta"
625 elseif a:colour == "purple"
627 elseif a:colour == "darkred"
629 elseif a:colour == "red"
633 " Colours which cterm*g doesn't recognise.
634 if a:colour == "purple"
642 au StatusLine VimEnter * call Highlight_StatusLine("")
644 " Show numbers by default.
645 au Display VimEnter * if ! Uncluttered_Buffer() | call Number(0) | endif
649 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
650 " Handle options only available in Vim 5.4 and above.
651 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
652 if version >= "504" "{{{1
655 " Reuse windows when using sbuffer.
658 " Vim 5 requires a 'n setting for viminfo.
663 " Allow persistent variable saving for localvimrc.
666 " Do we have Unicode?
667 fun! Has_Unicode() "{{{2
668 if ! has('multi_byte')
676 if &tenc =~? '^u\(tf\|cs\)'
680 if ! strlen(&tenc) && &enc =~? '^u\(tf\|cs\)'
687 " Helper for status line.
689 fun! Show_Encoding() "{{{2
701 if bufname("%") == ""
720 " Don't return anything if the encoding is utf-8.
727 return l:symbol . l:enc . ","
730 " Helper for status line.
731 " Show space, underscore or dollar sign depending on list mode.
732 fun! Show_List() "{{{2
754 " Helper for status line.
755 " Show c or C to denote case-sensitivity.
756 fun! Show_Case() "{{{2
764 " Helper for status line.
766 fun! Show_DOS() "{{{2
773 " Helper for status line.
774 " Show the size of the tabstop.
775 fun! Show_Tabstop() "{{{2
787 " Helper for status line.
788 " Show p when paste mode is on.
789 fun! Show_Paste() "{{{2
797 " Helper for status line.
798 " Show v when virtualedit mode is block, insert or onemore.
799 " Show V when virtualedit mode is all.
800 fun! Show_VirtualEdit() "{{{2
801 if ! has("virtualedit")
814 " Helper for status line.
815 " Show U when persistent undo is on.
816 " Show u when persistent undo is off but an undofile exists.
817 fun! Show_Undo() "{{{2
818 if ! exists("&undofile")
824 elseif filereadable(undofile(expand("%")))
831 " Helper for status line.
832 " Show alternate buffer number and name.
833 fun! Show_Alt() "{{{2
834 let l:alt = bufnr("#")
835 if l:alt < 0 || l:alt == bufnr("") || ! b:iainalt
839 return " " . l:alt . ": " . expand("#:t")
842 " Helper for status line.
843 " Show scrollbind or cursorbind.
844 fun! Show_Bind() "{{{2
863 " Helper for status line.
864 " Show marker if searchforward is unset.
865 fun! Show_SearchForward() "{{{2
878 " Helper for status line.
879 " Show marks set in cursor line.
880 fun! Show_Marks() "{{{2
881 if ! exists("g:iainsigns")
887 let l:signs = g:iainsigns
889 let l:cursorline = line(".")
890 while strlen(l:signs)
891 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=>-][^ ]\+')
892 let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "")
893 let l:ascii = matchstr(l:sign, '^:.')
894 let l:mark = substitute(l:sign, '^\(:.\)*[.=>-]', "", "")
896 let l:ascii = substitute(l:ascii, '^:', "", "")
900 let l:ascii = substitute(l:ascii, '"', '\\"', "")
905 let l:line = "'" . l:ascii
908 " Ignore cursor line which will always match.
910 if l:cursorline == line(l:line)
911 let l:marks = l:marks . l:mark
915 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
921 return "M:" . l:marks . " "
925 " Helper for status lines.
926 " Show Space plugin command.
927 fun! Show_Space() "{{{2
928 if exists("*GetSpaceMovement")
929 let l:ret = GetSpaceMovement()
932 let l:ret = "▭" . l:ret . Show_SearchForward()
934 let l:ret = "[" . l:ret . Show_SearchForward() . "]"
939 return Show_SearchForward()
943 " Show the status line.
944 fun! Show_StatusLine() "{{{2
945 if ! has("statusline")
950 " User{N} highlights %{N}*.
951 " Named highlight groups %#group% aren't available until Vim 7.
955 " sl1 contains left-aligned stuff.
956 " sl2 contains stuff shown only when verbose mode is enabled.
957 " sl3 contains right-aligned stuff.
958 let l:sl1='%2n\:\ %<' . l:bold . '%f' . l:normal . '\ [%{Show_Encoding()}%{Show_DOS()}%{Show_List()}%{Show_Bind()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%{Show_VirtualEdit()}%{Show_Undo()}%Y%M%R%{Show_Space()}]%{Show_Alt()}\ '
959 let l:sl3='%{Show_Marks()}L:' . l:bold . '%4.6l' . l:normal . '/%-4.6L\ C:' . l:bold . '%3.6c%V' . l:normal . '\ \|\ %P'
962 let l:hexformat='0\x%02B'
965 let l:sl1=l:sl1 . v:version . '\ %='
966 let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
968 let l:sl1=l:sl1 . '%='
971 exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
974 " Show the status line for the first time.
975 call Show_StatusLine()
978 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
979 " Handle options only available in Vim 6 and above.
980 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
981 if version >= "600" "{{{1
984 if has("win32") || has("win64")
988 " Remember quickfix state.
993 " Set indenting by filetype.
996 " Less intrusive syntax highlighting.
998 " The :syntax enable command tries to source the syntax.vim runtime script.
999 " Parsing this .vimrc will fail if for some reason the runtime doesn't
1000 " exist, as could be the case if the binary was installed with no support
1001 " files. GNU On Windows is one example of an incomplete installation.
1009 if has("gui_running")
1010 if has("win32") || has("win64")
1011 exe "silent se guifont=DejaVu_Sans_Mono:h10:cANSI"
1013 exe "silent se guifont=DejaVu\\ Sans\\ Mono\\ 10"
1016 if has("gui_running") || &t_Co > 16
1017 exe "silent colo iain"
1020 " Ignore whitespace when diffing.
1022 se diffopt=filler,iwhite
1027 " Remember that we are opening the quickfix window.
1028 au Mode BufWinEnter quickfix let g:quickfixing=1
1029 au Mode BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
1032 " Allow in-place editing of crontabs.
1033 au Mode FileType crontab set backupcopy=yes
1036 " Make * and # work the way you expect in visual mode.
1037 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
1038 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
1040 " Set mark and update highlighting.
1042 au Signs BufReadPost * call <SID>Highlight_Signs()
1043 au Signs CursorHold * call <SID>Highlight_Signs()
1046 " Helper to set buffer variable for a given sign.
1047 fun! <SID>Prep_Sign(sign) "{{{2
1048 if ! exists("b:sign" . a:sign) || ! g:marksigns
1049 exe "let b:sign" . a:sign . "=0"
1053 fun! <SID>Place_Sign(number, line, old, name) "{{{2
1058 exe "sign unplace " . (g:firstsign + a:number) . " buffer=" . bufnr("")
1059 " Don't place the sign if it would conflict with the last change sign.
1060 exe "sign place " . (g:firstsign + a:number) . " line=" . a:line . " name=" . a:name . " buffer=" . bufnr("")
1064 fun! <SID>Highlight_Signs(...) "{{{2
1065 if ! has("signs") || ! g:marksigns || Uncluttered_Buffer()
1069 let l:signs = g:iainsigns
1072 while strlen(l:signs)
1073 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=>-][^ ]\+')
1075 let l:name = substitute(l:sign, '[:.=>-].*', "", "")
1076 let l:var = tolower(l:name)
1077 let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "")
1078 let l:ascii = matchstr(l:sign, '^:.')
1079 let l:mark = substitute(l:sign, '^\(:.\)*[.=>-]', "", "")
1081 let l:ascii = substitute(l:ascii, '^:', "", "")
1083 let l:ascii = l:mark
1085 let l:ascii = substitute(l:ascii, '"', '\\"', "")
1090 let l:line = "'" . l:ascii
1093 call <SID>Prep_Sign(l:var)
1094 exe "let " . l:var . " = <SID>Place_Sign(" . l:i . ", line(\"" . l:line . "\"), b:sign" . l:var . ", \"Mark" . l:name . "\")"
1097 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
1102 fun! <SID>Cycle_Signs(resize) "{{{2
1107 let g:marksigns = ! g:marksigns
1109 " Retrofit arrays on to Vim 6.
1110 if ! exists("g:iainsigns")
1111 " Signs are defined in g:iainsigns. The syntax is as follows:
1113 " Sign ::= Name (':' Mark)* Type Symbol
1114 " Type ::= '=' | '-' | '.'
1116 " Signs with Type '=' will be highlighted with the MarkSign group.
1117 " Signs with Type '-' will be highlighted with the MarkLine group.
1118 " Signs with Type '.' will be highlighted with the MarkDot group.
1119 " Signs with Type '>' will be highlighted with the MarkArrow group.
1120 " Define the Mark where Symbol is not also the mark name, eg "']".
1121 let 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"
1123 let g:iainsigns = g:iainsigns . " Quote:\"=” Dash:'=’ Caret:^.ʌ Dot:..•"
1125 let g:iainsigns = g:iainsigns ." Cursor:o>▶"
1128 let g:iainsigns = g:iainsigns . " Quote=\" Dash=' Caret.^ Dot:..*"
1130 let g:iainsigns = g:iainsigns ." Cursor>o"
1136 " Signs to highlight marks.
1137 " Syntax won't work properly in Vim 6.
1138 let l:signs = g:iainsigns
1140 while strlen(l:signs)
1141 let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=>-][^ ]\+')
1143 let l:name = substitute(l:sign, '[:.=>-].*', "", "")
1144 let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "")
1145 let l:ascii = matchstr(l:sign, '^:.')
1146 let l:mark = substitute(l:sign, '^\(:.\)*[.=>-]', "", "")
1148 let l:ascii = substitute(l:ascii, '^:', "", "")
1149 let l:ascii = matchstr(l:ascii, '^.')
1151 let l:ascii = l:mark
1153 let l:ascii = substitute(l:ascii, '"', '\\"', "")
1154 let l:type = substitute(l:sign, '^:.', "", "")
1155 let l:type = matchstr(l:type, '^.')
1159 let l:hl = "texthl=MarkSign text="
1160 elseif l:type == "."
1161 let l:hl = "texthl=MarkDot text="
1162 elseif l:type == "-"
1163 let l:hl = "texthl=MarkLine text="
1164 elseif l:type == ">"
1165 let l:hl = "texthl=MarkArrow text="
1168 exe "sign define Mark" . l:name . " " . l:hl . l:mark
1170 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
1174 call Resize_Columns("+", 2)
1176 call <SID>Highlight_Signs()
1180 exe "sign unplace " . (g:firstsign + l:i)
1184 let l:signs = g:iainsigns
1186 while strlen(l:signs)
1187 let l:sign = matchstr(l:signs, '^[A-Za-z]\+')
1189 exe "sign undefine Mark" . l:sign
1190 call <SID>Prep_Sign(tolower(l:sign))
1191 let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "")
1195 call Resize_Columns("-", 2)
1201 fun! Cycle_List() "{{{2
1202 " Pretty UTF-8 listchars.
1204 let basic='tab:⇥·,trail:…,extends:«,precedes:»'
1207 let basic=basic . ',nbsp:•'
1210 let basic='tab:\\_,trail:_,extends:<,precedes:>'
1213 let basic=basic . ',nbsp:+'
1217 let w:iainlist = w:iainlist + 1
1223 elseif w:iainlist == 1
1224 exec "setlocal lcs=" . basic
1227 exec "setlocal lcs=" . basic . "," . eol
1231 call Resize_Columns(Extra_Columns("list", "iainlist", " == 2"), 1)
1232 call Extra_Whitespace_Match()
1235 " Cycle between hex and decimal display of toolbar stuff.
1236 fun! Cycle_HexStatusLine() "{{{2
1238 let b:iainhex = ! b:iainhex
1239 call Show_StatusLine()
1242 " Cycle verbose display of toolbar stuff.
1243 fun! Cycle_VerboseStatusLine() "{{{2
1245 let b:iainverbose = ! b:iainverbose
1246 call Show_StatusLine()
1249 " Toggle quickfix window.
1250 fun! Cycle_Quickfix() "{{{2
1251 if ! has("quickfix")
1254 if g:quickfixing == 1
1262 " Toggle showing alternate buffer information.
1263 fun! Cycle_Alt() "{{{2
1265 let b:iainalt = ! b:iainalt
1266 call Show_StatusLine()
1269 " To be overridden later if applicable.
1270 fun! Extra_Whitespace_Match() "{{{2
1274 " Swap hex/decimal statusline with \x.
1275 call Mapping("x", ":call Cycle_HexStatusLine()<CR>")
1276 " Change statusline verbosity with \v.
1277 call Mapping("V", ":call Cycle_VerboseStatusLine()<CR>")
1278 " Cycle list styles with \l.
1279 call Mapping("l", ":call Cycle_List()<CR>")
1280 " Toggle tags with \t.
1281 call Mapping("t", ":Tlist<CR>")
1282 " Change foldmethod with \f.
1283 call Mapping("f", ":se foldenable!<CR>")
1284 " Toggle quickfix window with \q.
1285 call Mapping("q", ":call Cycle_Quickfix()<CR>")
1286 " Rerun filetype detection with \s. The s is for syntax, as this will be
1287 " updated as a side-effect.
1288 call Mapping("S", ":filetype detect<CR>")
1289 " Toggle marks with \m.
1290 call Mapping("m", ":call <SID>Cycle_Signs(1)<CR>")
1293 " Show signs by default.
1294 au Display VimEnter * call <SID>Cycle_Signs(0)
1298 nmap <A-u> <Plug>MoveLineHalfPageUp
1299 nmap <A-d> <Plug>MoveLineHalfPageDown
1300 vmap <A-u> <Plug>MoveBlockHalfPageUp
1301 vmap <A-d> <Plug>MoveBlockHalfPageDown
1304 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1305 " Handle options only available in Vim 7 and above.
1306 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1307 if version >= "700" "{{{1
1310 " Narrow buffer with \w.
1311 call Mapping("w", ":NarrowRegion<CR>", "n", "v")
1312 " Narrow window with \W.
1313 call Mapping("W", ":NarrowWindow<CR>", "n", "v")
1315 " Helper to show tab name.
1316 fun! <SID>TabName(label, gui) "{{{2
1317 let l:label = a:label
1319 let l:label = "No Name"
1321 let l:label = "[" . l:label . "]"
1324 let l:label = fnamemodify(l:label, ":t")
1325 if strlen(l:label) >= 18
1326 let l:label = l:label[0:17] . ".."
1332 " Find out if any buffer was modified.
1333 fun! <SID>TabModified(buflist) "{{{2
1335 while l:i < len(a:buflist)
1336 if getbufvar(a:buflist[l:i], "&modified") == 1
1345 fun! Show_TabLine() "{{{2
1346 let l:s = "%#TabLineFill#Tabs:"
1349 while l:i < tabpagenr("$")
1352 let l:buflist = tabpagebuflist(l:i)
1353 let l:winnr = tabpagewinnr(l:i)
1354 let l:n = tabpagewinnr(l:i, "$")
1355 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 0)
1356 let l:modified = <SID>TabModified(l:buflist)
1358 " Choose highlighting.
1359 if l:i == tabpagenr()
1360 let l:s .= "%#TabLineSel#[" . l:n . l:modified . " " . l:label . "]"
1362 let l:s .= "%#TabLine# " . l:n . l:modified . " " . l:label . " "
1367 let l:s .= "%#TabLine#%T"
1371 " Per tab label for the GUI.
1372 fun! Show_GUITabLine() "{{{2
1373 let l:buflist = tabpagebuflist(v:lnum)
1374 let l:winnr = tabpagewinnr(v:lnum)
1375 let l:s = tabpagewinnr(v:lnum, "$")
1376 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 1)
1377 let l:modified = <SID>TabModified(l:buflist)
1379 let l:s .= l:modified . " " . l:label
1383 " Handle searching in a BufExplorer window.
1384 fun! <SID>BufExplorer_Search(n) "{{{2
1386 let l:re = '^ *\d %'
1388 let l:re = "^ *" . a:n
1391 " Find matching line.
1392 let l:line = search(l:re, 'w')
1401 " Peek ahead to the next matching line.
1402 let l:next = search(l:re, 'w')
1404 " Select the buffer if the match is unambiguous.
1411 call cursor(l:line, 0)
1414 " Entering a BufExplorer window.
1415 fun! <SID>BufExplorer_Map() "{{{2
1416 for l:n in [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ]
1417 exec "nnoremap <buffer> <silent>" . l:n . " :call <SID>BufExplorer_Search(" . l:n . ")<CR>"
1422 se tabline=%!Show_TabLine()
1423 se guitablabel=%!Show_GUITabLine()
1427 au StatusLine CursorHoldI * call Highlight_StatusLine("H")
1428 au StatusLine CursorMovedI * call Highlight_StatusLine("h")
1429 au StatusLine FocusGained * call Highlight_StatusLine("F")
1430 au StatusLine FocusLost * call Highlight_StatusLine("f")
1431 au StatusLine InsertEnter * call Highlight_StatusLine("I")
1432 au StatusLine InsertChange * call Highlight_StatusLine("I")
1433 au StatusLine InsertLeave * call Highlight_StatusLine("i")
1436 au Signs CursorHoldI * call <SID>Highlight_Signs()
1437 au Signs InsertEnter * call <SID>Highlight_Signs()
1438 au Signs InsertLeave * call <SID>Highlight_Signs()
1441 au Mode BufEnter \[BufExplorer\] call <SID>BufExplorer_Map()
1444 " Limit the size of the popup menu when completing.
1445 if has("insert_expand")
1449 " Make diffs vertical by default.
1451 se diffopt+=vertical
1454 " Set size of numbers column.
1459 " Add "previous tab" mapping as gb.
1460 map gb :tabprevious<CR>:<CR>
1463 if has("gui_macvim")
1467 " Yet more GUI options. Add tabs.
1473 let g:p4EnableMenu=1
1474 let g:p4Presets='P4CONFIG'
1477 let g:bufExplorerShowRelativePath=1
1478 let g:bufExplorerSplitOutPathName=0
1481 let g:NERDSpaceDelims=1
1484 let g:localvimrc_persistent=1
1487 let g:Gitv_OpenHorizontal='auto'
1488 let g:Gitv_WipeAllOnClose=1
1491 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1492 " Handle options only available in Vim 7.2 and above.
1493 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1494 if version >= "702" "{{{1
1496 " http://vim.wikia.com/wiki/Highlight_unwanted_spaces
1497 augroup WhitespaceMatch
1499 au Display BufWinEnter * call Extra_Whitespace_Match()
1500 au Display Syntax * call Extra_Whitespace_Match()
1501 au Display BufWinLeave * call clearmatches()
1504 fun! Extra_Whitespace_Match() "{{{2
1506 " $ <before end of line>
1507 " \@<! <unless preceded by>
1508 " \%# <cursor position, ie when typing>
1509 let l:pattern = '\s\+\%#\@<!$'
1510 " Don't match single space in first column of diff.
1511 if &ft =~# '^diff$\|git'
1512 " \@! <unless also matching>
1513 " \(^\s$\) <a single whitespace>
1514 let l:pattern = '\(^\s$\)\@!' . l:pattern
1517 let l:hl = 'ctermfg=red guifg=red'
1519 " Underline if we aren't using listchars.
1520 let l:hl = l:hl . ' cterm=underline gui=underline'
1522 highlight clear ExtraWhitespace
1523 exe "highlight ExtraWhitespace " . l:hl
1524 if exists('w:whitespace_match_number')
1526 call matchdelete(w:whitespace_match_number)
1529 call matchadd('ExtraWhitespace', l:pattern, 10, w:whitespace_match_number)
1531 let w:whitespace_match_number = matchadd('ExtraWhitespace', l:pattern)
1535 call Extra_Whitespace_Match()
1540 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1541 " Handle options only available in Vim 7.3 and above.
1542 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1543 if version >= "703" "{{{1
1546 " Toggle persistent undo with \u.
1547 call Mapping("u", ":call <SID>Cycle_Undo()<CR>")
1548 " Remove persistent undo file with \U.
1549 call Mapping("U", ":call <SID>Clear_Undo()<CR>")
1551 " Toggle gundo window with \g.
1552 call Mapping("g", ":call gundo#GundoToggle()<CR>")
1554 " Use a persistent undo file if it exists.
1555 fun! <SID>Check_Undo() "{{{2
1556 if filereadable(undofile(expand("%")))
1561 " Toggle persistent undo for this buffer.
1562 fun! <SID>Cycle_Undo() "{{{2
1563 if has("persistent_undo")
1564 let &undofile = ! &undofile
1568 " Remove the persistent undo file for this buffer.
1569 fun! <SID>Clear_Undo() "{{{2
1570 if ! has("persistent_undo")
1576 let l:f = expand("%")
1581 let l:u = undofile(l:f)
1586 if ! filereadable(l:u) || ! filewritable(l:u)
1593 " Toggle ColorColumn at cursor position.
1594 fun! <SID>Cycle_ColorColumn() "{{{2
1599 let l:cc = &colorcolumn
1600 let l:column = col(".")
1601 let l:re = ",*\\<" . l:column . "\\>"
1603 let l:cc = substitute(l:cc, l:re, "", "g")
1605 let l:cc = l:cc . "," . l:column
1607 let &colorcolumn = substitute(l:cc, "^,*", "", "")
1611 " Enable showing ColorColumn at cursor position with \CC.
1612 call Mapping("CC", ":call <SID>Cycle_ColorColumn()<CR>")
1613 " Remove last shown ColorColumn with \Cc.
1614 call Mapping("Cc", ":let &colorcolumn=substitute(&colorcolumn, \",*[0-9]*$\", \"\", \"\")<CR>")
1615 " Remove all ColorColumns with \Cx.
1616 call Mapping("Cx", ":se colorcolumn=<CR>")
1619 " Use persistent undo if available.
1621 if has("persistent_undo")
1622 au File BufReadPost * call <SID>Check_Undo()
1625 if has("cursorbind")
1626 au Display WinEnter * if &diff | se cursorbind | endif
1630 " Mapping to reload the gundo window.
1632 au Mode BufEnter * if &ft == "gundo" | try | nnoremap <silent> <buffer> <unique> r :call gundo#GundoToggle()<CR>:call gundo#GundoToggle()<CR> | catch | endtry | endif
1637 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1638 " Handle options only available in Vim 7.4 and above.
1639 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1640 if version >= "704" "{{{1
1649 " Resize after startup.
1650 if version >= "500" "{{{1
1652 au Display VimEnter * call Startup_Resize()