1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 " Multi-version vimrc compatible with version 4 and above.
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 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
17 " No compatibility mode.
22 " And use spaces not tabs.
24 " And << and >> indent by 2.
27 " Allow backspace to delete before start of line.
32 " Show partial commands in the ruler.
34 " And always show the status line.
39 se cinkeys=0{,0},0),:,!^F,o,O,e
45 " Don't be bugged by messages at the bottom of the screen.
51 " Case-insensitive search.
53 " But override by typing capitals.
56 " Look for ctags in home directory first.
57 se tags=~/.tags,./tags,tags
59 " Don't timeout waiting to interpet, eg, <ESC>OA as an escape code.
62 " Use ^B to search backward when completing.
64 " Use ^L to show matching completions but don't select one.
65 inoremap <C-l> <C-n><C-p>
67 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
68 " Handle options only available in Vim 5 and above.
69 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
73 " Tell Vim we use dark backgrounds in our terminals.
74 if ! has("gui_running")
78 " Enable tab-completion prompting for commands.
80 " Don't list object files when globbing files to load.
81 se wildignore+=*.o,*.obj
82 " So there's no need to assign them low priority.
83 se suffixes-=*.o,*.obj
85 " Save sessions in UNIX format with / as file separator. This is
89 " Nuke any pre-existing autocommands.
92 " Save the current window width so we can restore it when we quit.
95 " More GUI options. Add icon, tearoffs and toolbar.
98 " Allow dynamic window resize even if we aren't in an xterm.
99 se t_WS=
\e[8;%p1%d;%p2%dt
101 " Highlight search results.
104 " Set graphical window title.
105 se titlestring=%{Show_TitleString()}
107 " Syntax highlighting. New versions will use syn enable instead.
112 " Use a discernably different colour to highlight the cursor which shows
113 " matching brackets. Our regular cursor is green so use blue instead of cyan.
114 hi MatchParen ctermbg=blue
121 " Set up our variables.
123 if ! exists("b:iainlist")
126 if ! exists("b:iainhex")
129 if ! exists("b:iainverbose")
130 let b:iainverbose = 0
132 if ! exists("b:iainstatus")
133 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
134 let b:iainstatus = "Fih"
136 if ! exists("g:iainextracolumns")
137 let g:iainextracolumns = 0
141 " Helper for status line.
142 " Show space, underscore or dollar sign depending on list mode.
148 elseif b:iainlist == 1
157 " Helper for status line.
158 " Show c or C to denote case-sensitivity.
167 " Helper for status line.
168 " Show the size of the tabstop.
173 " Helper for status line.
174 " Show p when paste mode is on.
183 " Show the window title.
184 fun! Show_TitleString()
188 let l:ts1=printf("%2d: %s", bufnr(""), expand('%t'))
190 return printf("%s (%s) %s", l:ts1, getcwd(), v:servername)
193 " Show the status line.
194 fun! Show_StatusLine()
196 let l:sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
197 let l:sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
200 let l:hexformat='0\x%02B'
203 let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
207 exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
210 " Toggle case-sensitivity.
215 " Grow or shrink the window size.
216 fun! Resize_Columns(op)
217 " XXX: This won't work inside screen.
218 " We should really detect whether it would work rather than assume it won't.
219 if &term =~ '^screen'
223 " Vim 5 hardcodes the size of numbers column to 8.
225 let l:numberwidth = &numberwidth
227 let l:numberwidth = 8
230 exec "se columns" . a:op . "=" . l:numberwidth
233 " Toggle number display.
236 let &number = ! &number
240 let l:num_numbers = 0
241 while l:i <= winnr("$")
242 if getwinvar(l:i, "&number") == 1
243 let l:num_numbers = l:num_numbers + 1
248 if l:num_numbers == 0
249 let g:iainextracolumns = 0
250 call Resize_Columns("-")
251 elseif g:iainextracolumns == 0
252 let g:iainextracolumns = 1
253 call Resize_Columns("+")
258 " Restore window size.
259 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
262 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
263 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
265 " Entering Make mode.
275 fun! MakeMode_unmap()
281 " Show the status line for the first time.
282 call Show_StatusLine()
284 " Function to create mappings with either a hardcoded \ or <Leader>.
285 fun! Mapping(keysequence,mapping)
287 exec "map \\" . a:keysequence . " " . a:mapping
289 exec "map <Leader>" . a:keysequence . " " . a:mapping
293 " Use - and = to create underlines.
294 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
295 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
297 " Change to ts=2 with \2.
298 call Mapping("2", ":se ts=2<CR>:<CR>")
299 " Change to ts=4 with \4.
300 call Mapping("4", ":se ts=4<CR>:<CR>")
301 " Change to ts=8 with \8.
302 call Mapping("8", ":se ts=8<CR>:<CR>")
303 " Change to ts=16 with \6.
304 call Mapping("6", ":se ts=16<CR>:<CR>")
305 " Change to ts=32 with \3.
306 call Mapping("3", ":se ts=32<CR>:<CR>")
307 " Toggle paste mode with \p.
308 call Mapping("p", ":se paste!<CR>:<CR>")
309 " Swap case-sensitivity with \c.
310 call Mapping("c", ":call Invert_Case()<CR>:<CR>")
311 " Change number mode with \n.
312 call Mapping("n", ":call Number()<CR>:<CR>")
313 " Expand or shrink window size with \> and \<.
314 call Mapping(">", ":call Resize_Columns('+')<CR>:<CR>")
315 call Mapping("<", ":call Resize_Columns('-')<CR>:<CR>")
316 " Clear search pattern with \/.
317 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
319 " Forget the Ex mode mapping.
322 " Vim tip 99: What's the highlighting group under the cursor?
323 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>")
327 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
328 " Handle options only available in Vim 6 and above.
329 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
333 " Remember quickfix state.
336 " Set indenting by filetype.
339 " Less intrusive syntax highlighting.
343 if has("gui_running")
344 se guifont=DejaVu\ Sans\ Mono\ 10
346 hi LineNr guibg=#303030
354 se guifont=DejaVu_Sans_Mono:h10:cANSI
356 hi! link TabLineSel StatusLine
357 hi! link TabLine StatusLineNC
359 " Limit the size of the popup menu when completing.
362 " Ignore whitespace when diffing.
363 se diffopt=filler,iwhite
365 " Expand window when doing a vertical diff.
370 " Remember that we are opening the quickfix window.
371 au BufWinEnter quickfix let g:quickfixing=1
372 au BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
374 " Allow in-place editing of crontabs.
375 au FileType crontab set backupcopy=yes
377 " Make * and # work the way you expect in visual mode.
378 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
379 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
383 let basic='tab:\\_,trail:_,extends:<,precedes:>'
385 let b:iainlist = b:iainlist + 1
391 elseif b:iainlist == 1
392 exec "set lcs=" . basic
395 exec "set lcs=" . basic . ",eol:$"
400 " Cycle between hex and decimal display of toolbar stuff.
401 fun! Cycle_HexStatusLine()
403 let b:iainhex = ! b:iainhex
404 call Show_StatusLine()
407 " Cycle verbose display of toolbar stuff.
408 fun! Cycle_VerboseStatusLine()
410 let b:iainverbose = ! b:iainverbose
411 call Show_StatusLine()
414 " Toggle quickfix window.
415 fun! Cycle_Quickfix()
416 if g:quickfixing == 1
424 " Swap hex/decimal statusline with \x.
425 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
426 " Change statusline verbosity with \v.
427 call Mapping("v", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
428 " Cycle list styles with \l.
429 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
430 " Toggle tags with \t.
431 call Mapping("t", ":Tlist<CR>")
432 " Change foldmethod with \f.
433 call Mapping("f", ":se foldenable!<CR>:<CR>")
434 " Toggle quickfix window with \q.
435 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
436 " Rerun filetype detection with \s. The s is for syntax, as this will be
437 " updated as a side-effect.
438 call Mapping("s", ":filetype detect<CR>:<CR>")
440 " Change status bar colour when various things happen.
441 fun! Highlight_StatusLine(flag)
442 " Get current status.
445 " Change the status based on the flag. XXX: Does Vim let us to do flags?
446 let re = "[" . tolower(a:flag) . toupper(a:flag) . "]"
447 let b:iainstatus = substitute(b:iainstatus, re, a:flag, "")
450 let s:colour = "darkblue"
451 let s:termcolour = ""
452 let s:term88colour = "17"
453 let s:term256colour = "17"
454 " Maybe override depending on status.
455 if b:iainstatus =~# "H"
456 if b:iainstatus =~# "I"
457 " Held in insert mode. Add extra highlight if we don't have focus.
458 if b:iainstatus =~# "f"
459 let s:colour = "darkred"
460 let s:term88colour = "32"
461 let s:term256colour = "88"
463 let s:colour = "darkmagenta"
464 let s:term88colour = "33"
465 let s:term256colour = "90"
469 if b:iainstatus =~# "I"
470 " Regular insert mode.
471 let s:colour = "darkmagenta"
472 let s:term88colour = "33"
473 let s:term256colour = "90"
478 let s:termcolour = s:term88colour
480 let s:termcolour = s:term256colour
482 let s:termcolour = s:colour
485 exec "highlight StatusLine guifg=white guibg=" . s:colour . " ctermbg=white ctermfg=" . s:termcolour
488 call Highlight_StatusLine("")
491 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
492 " Handle options only available in Vim 7 and above.
493 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
497 " Helper to show tab name.
498 fun! <SID>TabName(label, gui)
499 let l:label = a:label
501 let l:label = "No Name"
503 let l:label = "[" . l:label . "]"
506 let l:label = fnamemodify(l:label, ":t")
507 if strlen(l:label) >= 18
508 let l:label = l:label[0:17] . ".."
514 " Find out if any buffer was modified.
515 fun! <SID>TabModified(buflist)
517 while i < len(a:buflist)
518 if getbufvar(a:buflist[l:i], "&modified") == 1
528 let l:s = "%#TabLineFill#Tabs:"
531 while l:i < tabpagenr("$")
534 let l:buflist = tabpagebuflist(l:i)
535 let l:winnr = tabpagewinnr(l:i)
536 let l:n = tabpagewinnr(l:i, "$")
537 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 0)
538 let l:modified = <SID>TabModified(l:buflist)
540 " Choose highlighting.
541 if l:i == tabpagenr()
542 let l:s .= "%#TabLineSel#[" . l:n . l:modified . " " . l:label . "]"
544 let l:s .= "%#TabLine# " . l:n . l:modified . " " . l:label . " "
549 let l:s .= "%#TabLine#%T"
553 " Per tab label for the GUI.
554 fun! Show_GUITabLine()
555 let l:buflist = tabpagebuflist(v:lnum)
556 let l:winnr = tabpagewinnr(v:lnum)
557 let l:s = tabpagewinnr(v:lnum, "$")
558 let l:label = <SID>TabName(bufname(l:buflist[l:winnr - 1]), 1)
559 let l:modified = <SID>TabModified(l:buflist)
561 let l:s .= l:modified . " " . l:label
565 se tabline=%!Show_TabLine()
566 se guitablabel=%!Show_GUITabLine()
568 au CursorHoldI * call Highlight_StatusLine("H")
569 au CursorMovedI * call Highlight_StatusLine("h")
570 au FocusGained * call Highlight_StatusLine("F")
571 au FocusLost * call Highlight_StatusLine("f")
572 au InsertEnter * call Highlight_StatusLine("I")
573 au InsertLeave * call Highlight_StatusLine("i")
575 " Make diffs vertical by default.
578 " Set size of numbers column.
581 " Add "previous tab" mapping as gb.
582 map gb :tabprevious<CR>:<CR>
589 " Yet more GUI options. Add tabs.
594 let g:p4Presets='P4CONFIG'