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 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
63 " Handle options only available in Vim 5 and above.
64 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
68 " Tell Vim we use dark backgrounds in our terminals.
69 if ! has("gui_running")
73 " Enable tab-completion prompting for commands.
75 " Don't list object files when globbing files to load.
76 se wildignore+=*.o,*.obj
77 " So there's no need to assign them low priority.
78 se suffixes-=*.o,*.obj
80 " Save sessions in UNIX format with / as file separator. This is
84 " Nuke any pre-existing autocommands.
87 " Save the current window width so we can restore it when we quit.
90 " More GUI options. Add icon, tearoffs and toolbar.
93 " Allow dynamic window resize even if we aren't in an xterm.
94 se t_WS=
\e[8;%p1%d;%p2%dt
96 " Highlight search results.
99 " Set graphical window title.
100 se titlestring=%{Show_TitleString()}
102 " Syntax highlighting. New versions will use syn enable instead.
107 " Use a discernably different colour to highlight the cursor which shows
108 " matching brackets. Our regular cursor is green so use blue instead of cyan.
109 hi MatchParen ctermbg=blue
116 " Set up our variables.
118 if ! exists("b:iainlist")
121 if ! exists("b:iainhex")
124 if ! exists("b:iainverbose")
125 let b:iainverbose = 0
127 if ! exists("b:iainstatus")
128 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
129 let b:iainstatus = "Fih"
131 if ! exists("g:iainextracolumns")
132 let g:iainextracolumns = 0
136 " Helper for status line.
137 " Show space, underscore or dollar sign depending on list mode.
143 elseif b:iainlist == 1
152 " Helper for status line.
153 " Show c or C to denote case-sensitivity.
162 " Helper for status line.
163 " Show the size of the tabstop.
168 " Helper for status line.
169 " Show p when paste mode is on.
178 " Show the window title.
179 fun! Show_TitleString()
183 let l:ts1=printf("%2d: %s", bufnr(""), expand('%t'))
185 return printf("%s (%s) %s", l:ts1, getcwd(), v:servername)
188 " Show the status line.
189 fun! Show_StatusLine()
191 let l:sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
192 let l:sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
195 let l:hexformat='0\x%02B'
198 let l:sl2=l:hexformat . '\ \|\ P:%4.6o\ '
202 exec "set statusline=" . l:sl1 . l:sl2 . l:sl3
205 " Toggle case-sensitivity.
210 " Grow or shrink the window size.
211 fun! Resize_Columns(op)
212 " XXX: This won't work inside screen.
213 " We should really detect whether it would work rather than assume it won't.
214 if &term =~ '^screen'
218 " Vim 5 hardcodes the size of numbers column to 8.
220 let l:numberwidth = &numberwidth
222 let l:numberwidth = 8
225 exec "se columns" . a:op . "=" . l:numberwidth
228 " Toggle number display.
231 let &number = ! &number
234 let l:num_numbers = 0
235 while l:i <= winnr("$")
236 if getwinvar(l:i, "&number") == 1
237 let l:num_numbers = l:num_numbers + 1
242 if l:num_numbers == 0
243 let g:iainextracolumns = 0
244 call Resize_Columns("-")
245 elseif g:iainextracolumns == 0
246 let g:iainextracolumns = 1
247 call Resize_Columns("+")
251 " Restore window size.
252 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
255 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
256 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
258 " Entering Make mode.
268 fun! MakeMode_unmap()
274 " Show the status line for the first time.
275 call Show_StatusLine()
277 " Function to create mappings with either a hardcoded \ or <Leader>.
278 fun! Mapping(keysequence,mapping)
280 exec "map \\" . a:keysequence . " " . a:mapping
282 exec "map <Leader>" . a:keysequence . " " . a:mapping
286 " Use - and = to create underlines.
287 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
288 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
290 " Change to ts=2 with \2.
291 call Mapping("2", ":se ts=2<CR>:<CR>")
292 " Change to ts=4 with \4.
293 call Mapping("4", ":se ts=4<CR>:<CR>")
294 " Change to ts=8 with \8.
295 call Mapping("8", ":se ts=8<CR>:<CR>")
296 " Change to ts=16 with \6.
297 call Mapping("6", ":se ts=16<CR>:<CR>")
298 " Change to ts=32 with \3.
299 call Mapping("3", ":se ts=32<CR>:<CR>")
300 " Toggle paste mode with \p.
301 call Mapping("p", ":se paste!<CR>:<CR>")
302 " Swap case-sensitivity with \c.
303 call Mapping("c", ":call Invert_Case()<CR>:<CR>")
304 " Change number mode with \n.
305 call Mapping("n", ":call Number()<CR>:<CR>")
306 " Expand or shrink window size with \> and \<.
307 call Mapping(">", ":call Resize_Columns('+')<CR>:<CR>")
308 call Mapping("<", ":call Resize_Columns('-')<CR>:<CR>")
309 " Clear search pattern with \/.
310 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
312 " Forget the Ex mode mapping.
315 " Vim tip 99: What's the highlighting group under the cursor?
316 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>")
320 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
321 " Handle options only available in Vim 6 and above.
322 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
326 " Remember quickfix state.
329 " Set indenting by filetype.
332 " Less intrusive syntax highlighting.
336 if has("gui_running")
337 se guifont=DejaVu\ Sans\ Mono\ 10
339 hi LineNr guibg=#303030
347 se guifont=DejaVu_Sans_Mono:h10:cANSI
350 " Ignore whitespace when diffing.
351 se diffopt=filler,iwhite
353 " Expand window when doing a vertical diff.
358 " Remember that we are opening the quickfix window.
359 au BufWinEnter quickfix let g:quickfixing=1
360 au BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
362 " Allow in-place editing of crontabs.
363 au FileType crontab set backupcopy=yes
365 " Make * and # work the way you expect in visual mode.
366 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
367 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
371 let basic='tab:\\_,trail:_,extends:<,precedes:>'
373 let b:iainlist = b:iainlist + 1
379 elseif b:iainlist == 1
380 exec "set lcs=" . basic
383 exec "set lcs=" . basic . ",eol:$"
388 " Cycle between hex and decimal display of toolbar stuff.
389 fun! Cycle_HexStatusLine()
391 let b:iainhex = ! b:iainhex
392 call Show_StatusLine()
395 " Cycle verbose display of toolbar stuff.
396 fun! Cycle_VerboseStatusLine()
398 let b:iainverbose = ! b:iainverbose
399 call Show_StatusLine()
402 " Toggle quickfix window.
403 fun! Cycle_Quickfix()
404 if g:quickfixing == 1
412 " Swap hex/decimal statusline with \x.
413 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
414 " Change statusline verbosity with \v.
415 call Mapping("v", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
416 " Cycle list styles with \l.
417 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
418 " Toggle tags with \t.
419 call Mapping("t", ":Tlist<CR>")
420 " Change foldmethod with \f.
421 call Mapping("f", ":se foldenable!<CR>:<CR>")
422 " Toggle quickfix window with \q.
423 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
424 " Rerun filetype detection with \s. The s is for syntax, as this will be
425 " updated as a side-effect.
426 call Mapping("s", ":filetype detect<CR>:<CR>")
428 " Change status bar colour when various things happen.
429 fun! Highlight_StatusLine(flag)
430 " Get current status.
433 " Change the status based on the flag. XXX: Does Vim let us to do flags?
434 let re = "[" . tolower(a:flag) . toupper(a:flag) . "]"
435 let b:iainstatus = substitute(b:iainstatus, re, a:flag, "")
438 let s:colour = "darkblue"
439 let s:termcolour = ""
440 let s:term88colour = "17"
441 let s:term256colour = "17"
442 " Maybe override depending on status.
443 if b:iainstatus =~# "H"
444 if b:iainstatus =~# "I"
445 " Held in insert mode. Add extra highlight if we don't have focus.
446 if b:iainstatus =~# "f"
447 let s:colour = "darkred"
448 let s:term88colour = "32"
449 let s:term256colour = "88"
451 let s:colour = "darkmagenta"
452 let s:term88colour = "33"
453 let s:term256colour = "90"
457 if b:iainstatus =~# "I"
458 " Regular insert mode.
459 let s:colour = "darkmagenta"
460 let s:term88colour = "33"
461 let s:term256colour = "90"
466 let s:termcolour = s:term88colour
468 let s:termcolour = s:term256colour
470 let s:termcolour = s:colour
473 exec "highlight StatusLine guifg=white guibg=" . s:colour . " ctermbg=white ctermfg=" . s:termcolour
476 call Highlight_StatusLine("")
479 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
480 " Handle options only available in Vim 7 and above.
481 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
485 au CursorHoldI * call Highlight_StatusLine("H")
486 au CursorMovedI * call Highlight_StatusLine("h")
487 au FocusGained * call Highlight_StatusLine("F")
488 au FocusLost * call Highlight_StatusLine("f")
489 au InsertEnter * call Highlight_StatusLine("I")
490 au InsertLeave * call Highlight_StatusLine("i")
492 " Make diffs vertical by default.
495 " Set size of numbers column.
498 " Add "previous tab" mapping as gb.
508 let g:p4Presets='P4CONFIG'