1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4 " Multi-version vimrc compatible with version 4 and above.
5 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
7 " Note that "if <condition> | call Something() | endif" syntax is unsupported
8 " in Vim 4 so we write all our functions out the long way. It does work in
9 " autocommand definitions, however.
11 " Vim 4 complains if version isn't set in the configuration file.
14 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
15 " Handle options safe to use in version 4. Vim 4 parses but ignores the
16 " "if version" syntax used later in this file so we don't use it. No attempt
17 " is made to make this configuration compatible with Vim 3.
18 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
19 " No compatibility mode.
24 " And use spaces not tabs.
26 " And << and >> indent by 2.
29 " Allow backspace to delete before start of line.
34 " Show partial commands in the ruler.
36 " And always show the status line.
41 se cinkeys=0{,0},0),:,!^F,o,O,e
47 " Don't be bugged by messages at the bottom of the screen.
53 " Case-insensitive search.
55 " But override by typing capitals.
58 " Look for ctags in home directory first.
59 se tags=~/.tags,./tags,tags
61 " Don't timeout waiting to interpet, eg, <ESC>OA as an escape code.
64 " Function to create mappings with either a hardcoded \ or <Leader>.
65 fun! Mapping(keysequence,mapping)
67 exec "map \\" . a:keysequence . " " . a:mapping
69 exec "map <Leader>" . a:keysequence . " " . a:mapping
73 " Use - and = to create underlines.
74 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
75 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
77 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
78 " Handle options only available in Vim 5 and above.
79 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
83 " Tell Vim we use dark backgrounds in our terminals.
84 if ! has("gui_running")
88 " Vim 5 hardcodes the size of numbers column to 8.
91 " Save sessions in UNIX format with / as file separator. This is
95 " Nuke any pre-existing autocommands.
98 " Save the current window width so we can restore it when we quit.
101 " More GUI options. Add icon, tearoffs and toolbar.
104 " Allow dynamic window resize even if we aren't in an xterm.
105 se t_WS=
\e[8;%p1%d;%p2%dt
107 " Highlight search results.
110 " Syntax highlighting.
113 " Use a discernably different colour to highlight the cursor which shows
114 " matching brackets. Our regular cursor is green so use blue instead of cyan.
115 hi MatchParen ctermbg=blue
122 " Set up our variables.
124 if ! exists("b:iainlist")
127 if ! exists("b:iainhex")
130 if ! exists("b:iainverbose")
131 let b:iainverbose = 0
133 if ! exists("b:iainstatus")
134 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
135 let b:iainstatus = "Fih"
139 " Helper for status line.
140 " Show space, underscore or dollar sign depending on list mode.
146 elseif b:iainlist == 1
155 " Helper for status line.
156 " Show c or C to denote case-sensitivity.
165 " Helper for status line.
166 " Show the size of the tabstop.
171 " Helper for status line.
172 " Show p when paste mode is on.
181 " Show the status line.
182 fun! Show_StatusLine()
184 let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
185 let sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
188 let hexformat='0\x%02B'
191 let sl2=hexformat . '\ \|\ P:%4.6o\ '
195 exec "set statusline=" . sl1 . sl2 . sl3
198 " Toggle case-sensitivity.
203 " Restore window size.
204 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
207 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
208 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
210 " Entering Make mode.
217 fun! MakeMode_unmap()
222 " Show the status line for the first time.
223 call Show_StatusLine()
225 " Change to ts=2 with \2.
226 call Mapping("2", ":se ts=2<CR>:<CR>")
227 " Change to ts=4 with \4.
228 call Mapping("4", ":se ts=4<CR>:<CR>")
229 " Change to ts=8 with \8.
230 call Mapping("8", ":se ts=8<CR>:<CR>")
231 " Change to ts=16 with \6.
232 call Mapping("6", ":se ts=16<CR>:<CR>")
233 " Change to ts=32 with \3.
234 call Mapping("3", ":se ts=32<CR>:<CR>")
235 " Toggle paste mode with \p.
236 call Mapping("p", ":se paste!<CR>:<CR>")
237 " Swap case-sensitivity with \c.
238 call Mapping("c", ":call Invert_Case()<CR>:<CR>")
239 " Change number mode with \n.
240 call Mapping("n", ":se number!<CR>:<CR>")
241 " Expand or shrink window size with \> and \<. For use after toggling number.
242 call Mapping(">", ":exe 'se columns+=' . numberwidth<CR>:<CR>")
243 call Mapping("<", ":exe 'se columns-=' . numberwidth<CR>:<CR>")
244 " Clear search pattern with \/.
245 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
247 " Forget the Ex mode mapping.
252 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
253 " Handle options only available in Vim 6 and above.
254 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
258 " Remember quickfix state.
261 " Set indenting by filetype.
264 " Less intrusive syntax highlighting.
268 if has("gui_running")
269 se guifont=DejaVu\ Sans\ Mono\ 10
273 se guifont=DejaVu_Sans_Mono:h10:cANSI
276 " Ignore whitespace when diffing.
277 se diffopt=filler,iwhite
279 " Expand window when doing a vertical diff.
285 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
287 " Remember that we are opening the quickfix window.
288 au BufWinEnter quickfix let g:quickfixing=1
289 au BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
291 " Make * and # work the way you expect in visual mode.
292 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
293 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
297 let basic='tab:\\_,trail:_,extends:<,precedes:>'
299 let b:iainlist = b:iainlist + 1
305 elseif b:iainlist == 1
306 exec "set lcs=" . basic
309 exec "set lcs=" . basic . ",eol:$"
314 " Cycle between hex and decimal display of toolbar stuff.
315 fun! Cycle_HexStatusLine()
317 let b:iainhex = ! b:iainhex
318 call Show_StatusLine()
321 " Cycle verbose display of toolbar stuff.
322 fun! Cycle_VerboseStatusLine()
324 let b:iainverbose = ! b:iainverbose
325 call Show_StatusLine()
328 " Toggle quickfix window.
329 fun! Cycle_Quickfix()
330 if g:quickfixing == 1
338 " Swap hex/decimal statusline with \x.
339 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
340 " Change statusline verbosity with \v.
341 call Mapping("v", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
342 " Cycle list styles with \l.
343 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
344 " Toggle tags with \t.
345 call Mapping("t", ":Tlist<CR>")
346 " Change foldmethod with \f.
347 call Mapping("f", ":se foldenable!<CR>:<CR>")
348 " Toggle quickfix window with \q.
349 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
350 " Rerun filetype detection with \s. The s is for syntax, as this will be
351 " updated as a side-effect.
352 call Mapping("s", ":filetype detect<CR>:<CR>")
354 " Change status bar colour when various things happen.
355 fun! Highlight_StatusLine(flag)
356 " Get current status.
359 " Change the status based on the flag. XXX: Does Vim let us to do flags?
360 let re = "[" . tolower(a:flag) . toupper(a:flag) . "]"
361 let b:iainstatus = substitute(b:iainstatus, re, a:flag, "")
364 let s:colour = "darkblue"
365 let s:termcolour = ""
366 let s:term88colour = "17"
367 let s:term256colour = "17"
368 " Maybe override depending on status.
369 if b:iainstatus =~# "H"
370 if b:iainstatus =~# "I"
371 " Held in insert mode. Add extra highlight if we don't have focus.
372 if b:iainstatus =~# "f"
373 let s:colour = "darkmagenta"
375 let s:colour = "darkred"
377 let s:term88colour = "32"
378 let s:term256colour = "88"
381 if b:iainstatus =~# "I"
382 " Regular insert mode.
383 let s:colour = "darkred"
384 let s:term88colour = "32"
385 let s:term256colour = "88"
390 let s:termcolour = s:term88colour
392 let s:termcolour = s:term256colour
394 let s:termcolour = s:colour
397 exec "highlight StatusLine guifg=white guibg=" . s:colour . " ctermbg=white ctermfg=" . s:termcolour
400 call Highlight_StatusLine("")
403 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
404 " Handle options only available in Vim 7 and above.
405 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
409 au CursorHoldI * call Highlight_StatusLine("H")
410 au CursorMovedI * call Highlight_StatusLine("h")
411 au FocusGained * call Highlight_StatusLine("F")
412 au FocusLost * call Highlight_StatusLine("f")
413 au InsertEnter * call Highlight_StatusLine("I")
414 au InsertLeave * call Highlight_StatusLine("i")
416 " Make diffs vertical by default.
419 " Set size of numbers column.
422 " Add "previous tab" mapping as gb.