+ " No list.
+ return " "
+ elseif <SID>Has_Unicode()
+ if b:iainlist == 1
+ " Just tabs.
+ return "»"
+ else
+ " Full list.
+ return "¶"
+ endif
+ else
+ if b:iainlist == 1
+ return "_"
+ else
+ return "\$"
+ endif
+ endif
+endfun "}}}2
+
+" Helper for status line.
+" Show c or C to denote case-sensitivity.
+fun! Show_Case() "{{{2
+ if &ic
+ return "c"
+ else
+ return "C"
+ endif
+endfun "}}}2
+
+" Helper for status line.
+" Show the size of the tabstop.
+fun! Show_Tabstop() "{{{2
+ return &ts
+endfun "}}}2
+
+" Helper for status line.
+" Show p when paste mode is on.
+fun! Show_Paste() "{{{2
+ if &paste
+ return "p"
+ else
+ return ""
+ endif
+endfun "}}}2
+
+" Show the window title.
+fun! Show_TitleString() "{{{2
+ if bufname("") == ""
+ let l:ts1='Vim'
+ else
+ " Vim 5 doesn't have printf.
+ let l:ts1=bufnr("")
+ if l:ts1 < 10
+ let l:ts1=" " . l:ts1
+ endif
+ let l:ts1=l:ts1 . ": " . expand('%t')
+ endif
+ let l:ts1=l:ts1 . " (" . getcwd() . ")"
+ if has("clientserver")
+ let l:ts1=l:ts1 . " " . v:servername
+ endif
+ return l:ts1
+endfun "}}}2
+
+" Show the status line.
+fun! Show_StatusLine() "{{{2
+ call Iain_Vars()
+ let l:sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ '
+ let l:sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
+ let l:hexformat='%b'
+ if b:iainhex
+ let l:hexformat='0\x%02B'
+ endif
+ if b:iainverbose
+ let l:sl1=l:sl1 . v:version . '\ %='
+ let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
+ else
+ let l:sl1=l:sl1 . '%='
+ let l:sl2=''
+ endif
+ exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
+endfun "}}}2
+
+" Toggle case-sensitivity.
+fun! Invert_Case() "{{{2
+ let &ic = ! &ic
+endfun "}}}2
+
+" Grow or shrink the window size.
+fun! Resize_Columns(op, ...) "{{{2
+ if a:op == ""
+ return
+ endif
+
+ if a:0 == 0
+ " Vim 5 hardcodes the size of numbers column to 8.
+ if version >= "700"
+ let l:columns = &numberwidth
+ else
+ let l:columns = 8
+ endif
+ else
+ let l:columns = a:1
+ endif
+
+ exe "let l:resize=" . &columns . a:op . l:columns
+ let l:resize = "se columns=" . l:resize
+
+ " HACK: Inside screen there is an extra line for the status bar. Vim
+ " manages the resize by sending an escape sequence to set the number of
+ " lines and number of columns in one action. To do this it will first query
+ " the number of lines and then set <same number of lines> by <new number of
+ " columns>. Because of the extra line for the status bar this results in
+ " the real terminal being shrunk by a line. We ask for the terminal to grow
+ " by a line so it ends up actually being the same.
+ if &term =~ '^screen'
+ let l:resize = l:resize . " lines=" . (&lines + 1)
+ endif
+
+ exe l:resize
+endfun "}}}2
+
+" Set extra columns depending on window status.
+fun! Extra_Columns(extra, var, ...) "{{{2
+ if v:version < "700"
+ return ""
+ endif
+
+ call Iain_Vars()
+
+ if a:0 == 0
+ let l:condition = ""
+ else
+ let l:condition = a:1
+ endif
+
+ let l:i = 1
+ let l:num_windows = 0
+ while l:i <= winnr("$")
+ let l:val = 0
+ exe "if getwinvar(" . l:i . ", '" . a:var . "') " . l:condition . " | let l:val = 1 | endif"
+ if l:val
+ let l:num_windows = l:num_windows + 1
+ endif
+ let l:i = l:i + 1
+ endwhile
+
+ let l:extra = "g:iainextracolumns" . a:extra
+ exe "let l:val = " . l:extra
+
+ if l:num_windows == l:val
+ return ""
+ endif
+ exe "let " . l:extra . " = " . l:num_windows
+
+ if l:num_windows == 0
+ return "-"
+ elseif l:val == 0
+ return "+"
+ endif
+endfun "}}}2
+
+" Toggle number display.
+fun! Number(resize) "{{{2
+ call Iain_Vars()
+ let &number = ! &number
+
+ " Ensure we keep track of any extra columns even if we aren't resizing.
+ " This prevents confusion when number is set at startup.
+ let l:extra = Extra_Columns("number", "&number")
+
+ if a:resize
+ call Resize_Columns(l:extra)
+ endif
+endfun "}}}2
+
+" Restore window size.
+au Display VimLeave * if exists("g:oldcols") | call Resize_Columns("-", (&columns - g:oldcols)) | endif
+
+" Map Makefile mode.
+au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif
+au Mode BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
+
+" Entering Make mode.
+fun! MakeMode_map() "{{{2
+ call Iain_Vars()
+ let b:iainlist=1
+ call Cycle_List()
+ set ts=8
+ set noexpandtab
+endfun "}}}2
+
+" Leaving Make mode.
+fun! MakeMode_unmap() "{{{2
+ call Cycle_List()
+ set ts=2
+ set expandtab
+endfun "}}}2
+
+" Show the status line for the first time.
+call Show_StatusLine()
+
+" Function to create mappings with either a hardcoded \ or <Leader>.
+fun! Mapping(keysequence,mapping) "{{{2
+ if version < "600"
+ exec "map \\" . a:keysequence . " " . a:mapping
+ else
+ exec "map <Leader>" . a:keysequence . " " . a:mapping
+ endif
+endfun "}}}2
+
+" Use - and = to create underlines.
+call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
+call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
+
+" Change to ts=2 with \2.
+call Mapping("2", ":se ts=2<CR>:<CR>")
+" Change to ts=4 with \4.
+call Mapping("4", ":se ts=4<CR>:<CR>")
+" Change to ts=8 with \8.
+call Mapping("8", ":se ts=8<CR>:<CR>")
+" Change to ts=16 with \6.
+call Mapping("6", ":se ts=16<CR>:<CR>")
+" Change to ts=32 with \3.
+call Mapping("3", ":se ts=32<CR>:<CR>")
+" Toggle paste mode with \p.
+call Mapping("p", ":se paste!<CR>:<CR>")
+" Swap case-sensitivity with \c.
+call Mapping("C", ":call Invert_Case()<CR>:<CR>")
+" Change number mode with \n.
+call Mapping("n", ":call Number(1)<CR>:<CR>")
+" Expand or shrink window size with \> and \<.
+call Mapping(">", ":call Resize_Columns('+')<CR>:<CR>")
+call Mapping("<", ":call Resize_Columns('-')<CR>:<CR>")
+" Clear search pattern with \/.
+call Mapping("/", ":let @/=\"\"<CR>:<CR>")
+
+" Forget the Ex mode mapping.
+map Q <NOP>
+
+" Vim tip 99: What's the highlighting group under the cursor?
+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>")
+
+fun! Uncluttered_Buffer() "{{{2
+ if exists("uncluttered_buffer")
+ if uncluttered_buffer == 1
+ return 1
+ endif
+ endif
+
+ if version >= "600"
+ if &buftype != ''
+ return 1
+ endif
+ endif
+
+ if &ft == 'perforce'
+ return 1
+ endif
+
+ if &ft == 'svn'
+ return 1
+ endif
+
+ if &ft == 'gitcommit'
+ return 1
+ endif
+
+ return 0
+endfun "}}}2
+
+fun! Startup_Resize() "{{{2
+ let l:columns = 0
+
+ " Resize for numbers.
+ if &number
+ if version >= "700"
+ let l:columns = &numberwidth
+ else
+ let l:columns = 8
+ endif
+ endif
+
+ " Resize for signs.
+ if has("signs")
+ if g:marksigns
+ if version >= "600"
+ let l:columns = l:columns + 2
+ endif
+ endif
+ endif
+
+ if g:oldcols < (80 + l:columns)
+ call Resize_Columns("+", l:columns)
+ endif
+endfun "}}}2
+
+" Show numbers by default.
+au Display VimEnter * if ! Uncluttered_Buffer() | call Number(0) | endif
+
+" Position the compview plugin window.
+au Display BufEnter -SearchResults- set buftype=nowrite | set nonumber | wincmd J
+endif "}}}1
+
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Handle options only available in Vim 6 and above.
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+if version >= "600" "{{{1
+version 6.0
+
+if has("win32")
+ se encoding=utf-8
+endif
+
+" Remember quickfix state.
+let g:quickfixing=0
+
+" Set indenting by filetype.
+filetype indent on
+
+" Less intrusive syntax highlighting.
+syn enable
+
+" Set colours.
+if has("gui_running")
+ try
+ if has("win32")
+ se guifont=DejaVu_Sans_Mono:h10:cANSI
+ else
+ se guifont=DejaVu\ Sans\ Mono\ 10
+ endif
+ catch
+ endtry
+endif
+if has("gui_running") || &t_Co > 16
+ try
+ colo iain
+ catch
+ endtry
+endif
+
+" Ignore whitespace when diffing.
+se diffopt=filler,iwhite
+
+" Expand window when doing a vertical diff.
+if &diff
+ if &columns < 161
+ let &columns = &columns * 2
+ endif
+endif
+
+" Remember that we are opening the quickfix window.
+au Mode BufWinEnter quickfix let g:quickfixing=1
+au Mode BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
+
+" Allow in-place editing of crontabs.
+au Mode FileType crontab set backupcopy=yes
+
+" Make * and # work the way you expect in visual mode.
+vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
+vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
+
+" Set mark and update highlighting.
+if has("signs")
+ au Signs BufReadPost * call <SID>Highlight_Signs()
+ au Signs CursorHold * call <SID>Highlight_Signs()
+endif
+
+" Helper to set buffer variable for a given sign.
+fun! <SID>Prep_Sign(sign) "{{{2
+ if ! exists("b:sign" . a:sign) || ! g:marksigns
+ exe "let b:sign" . a:sign . "=0"
+ endif
+endfun "}}}2
+
+fun! <SID>Prep_Signs() "{{{2
+ call <SID>Prep_Sign("dot")
+ call <SID>Prep_Sign("dash")
+ call <SID>Prep_Sign("quote")
+ call <SID>Prep_Sign("caret")
+ call <SID>Prep_Sign("less")
+ call <SID>Prep_Sign("greater")
+ call <SID>Prep_Sign("left")
+ call <SID>Prep_Sign("right")
+ call <SID>Prep_Sign("squareleft")
+ call <SID>Prep_Sign("squareright")
+ call <SID>Prep_Sign("braceleft")
+ call <SID>Prep_Sign("braceright")
+ call <SID>Prep_Sign("a")
+ call <SID>Prep_Sign("b")
+ call <SID>Prep_Sign("c")
+ call <SID>Prep_Sign("d")
+ call <SID>Prep_Sign("e")
+ call <SID>Prep_Sign("f")
+ call <SID>Prep_Sign("A")
+ call <SID>Prep_Sign("B")
+ call <SID>Prep_Sign("C")
+ call <SID>Prep_Sign("D")
+ call <SID>Prep_Sign("E")
+ call <SID>Prep_Sign("F")
+endfun! "}}}2
+
+fun! <SID>Place_Sign(number, line, old, name) "{{{2
+ if a:line == a:old
+ return a:old
+ endif
+
+ exe "sign unplace " . (g:firstsign + a:number) . " buffer=" . bufnr("")
+ " Don't place the sign if it would conflict with the last change sign.
+ exe "sign place " . (g:firstsign + a:number) . " line=" . a:line . " name=" . a:name . " buffer=" . bufnr("")
+ return a:line
+endfun "}}}2
+
+fun! <SID>Highlight_Signs(...) "{{{2
+ if ! has("signs") || ! g:marksigns || Uncluttered_Buffer()
+ return
+ endif
+
+ call <SID>Prep_Signs()
+
+ let b:signdot = <SID>Place_Sign(0, line("'."), b:signdot, "MarkDot")
+ let b:signdash = <SID>Place_Sign(1, line("''"), b:signdash, "MarkDash")
+ let b:signquote = <SID>Place_Sign(2, line("'\""), b:signquote, "MarkQuote")
+ let b:signcaret = <SID>Place_Sign(3, line("'^"), b:signcaret, "MarkCaret")
+ let b:signless = <SID>Place_Sign(4, line("'<"), b:signless, "MarkLess")
+ let b:signgreater = <SID>Place_Sign(5, line("'>"), b:signgreater, "MarkGreater")
+ let b:signleft = <SID>Place_Sign(6, line("'("), b:signleft, "MarkLeft")
+ let b:signright = <SID>Place_Sign(7, line("')"), b:signright, "MarkRight")
+ let b:signsquareleft = <SID>Place_Sign(8, line("'["), b:signsquareleft, "MarkSquareLeft")
+ let b:signsquareright = <SID>Place_Sign(9, line("']"), b:signsquareright, "MarkSquareRight")
+ let b:signbraceleft = <SID>Place_Sign(10, line("'{"), b:signbraceleft, "MarkBraceLeft")
+ let b:signbraceright = <SID>Place_Sign(11, line("'}"), b:signbraceright, "MarkBraceRight")
+
+ let b:signa = <SID>Place_Sign(12, line("'a"), b:signa, "Marka")
+ let b:signb = <SID>Place_Sign(13, line("'b"), b:signb, "Markb")
+ let b:signc = <SID>Place_Sign(15, line("'c"), b:signc, "Markc")
+ let b:signd = <SID>Place_Sign(16, line("'d"), b:signd, "Markd")
+ let b:signe = <SID>Place_Sign(17, line("'e"), b:signe, "Marke")
+ let b:signf = <SID>Place_Sign(18, line("'f"), b:signf, "Markf")
+ let b:signA = <SID>Place_Sign(19, line("'A"), b:signA, "MarkA")
+ let b:signB = <SID>Place_Sign(20, line("'B"), b:signB, "MarkB")
+ let b:signC = <SID>Place_Sign(21, line("'C"), b:signC, "MarkC")
+ let b:signD = <SID>Place_Sign(22, line("'D"), b:signD, "MarkD")
+ let b:signE = <SID>Place_Sign(23, line("'E"), b:signE, "MarkE")
+ let b:signF = <SID>Place_Sign(24, line("'F"), b:signF, "MarkF")
+endfun "}}}2
+
+" Toggle signs.
+fun! <SID>Cycle_Signs(resize) "{{{2
+ if ! has("signs")
+ return
+ endif
+ call Iain_Vars()
+ let g:marksigns = ! g:marksigns
+
+ if g:marksigns
+ " Signs to highlight marks.
+ " Syntax won't work properly in Vim 6.
+ if <SID>Has_Unicode()
+ sign define MarkDash text=’ texthl=MarkSign
+ sign define MarkDot text=• texthl=MarkDot
+ sign define MarkQuote text=” texthl=MarkSign
+ else
+ sign define MarkDash text=' texthl=MarkSign
+ sign define MarkDot text=* texthl=MarkDot
+ sign define MarkQuote text=" texthl=MarkSign
+ endif
+ sign define MarkCaret text=^ texthl=MarkDot
+ sign define MarkLess text=< texthl=MarkSign
+ sign define MarkGreater text=> texthl=MarkSign
+ sign define MarkLeft text=( texthl=MarkSign
+ sign define MarkRight text=) texthl=MarkSign
+ sign define MarkSquareLeft text=[ texthl=MarkSign
+ sign define MarkSquareRight text=] texthl=MarkSign
+ sign define MarkBraceLeft text={ texthl=MarkSign
+ sign define MarkBraceRight text=} texthl=MarkSign
+ sign define Marka text=a texthl=MarkSign linehl=MarkLine
+ sign define Markb text=b texthl=MarkSign linehl=MarkLine
+ sign define Markc text=c texthl=MarkSign linehl=MarkLine
+ sign define Markd text=d texthl=MarkSign linehl=MarkLine
+ sign define Marke text=e texthl=MarkSign linehl=MarkLine
+ sign define Markf text=f texthl=MarkSign linehl=MarkLine
+ sign define MarkA text=A texthl=MarkSign linehl=MarkLine
+ sign define MarkB text=B texthl=MarkSign linehl=MarkLine
+ sign define MarkC text=C texthl=MarkSign linehl=MarkLine
+ sign define MarkD text=D texthl=MarkSign linehl=MarkLine
+ sign define MarkE text=E texthl=MarkSign linehl=MarkLine
+ sign define MarkF text=F texthl=MarkSign linehl=MarkLine
+
+ if a:resize
+ call Resize_Columns("+", 2)
+ endif
+ call <SID>Highlight_Signs()