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 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
65 " Handle options only available in Vim 5 and above.
66 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
70 " Tell Vim we use dark backgrounds in our terminals.
71 if ! has("gui_running")
75 " Enable tab-completion prompting for commands.
77 " Don't list object files when globbing files to load.
78 se wildignore+=*.o,*.obj
79 " So there's no need to assign them low priority.
80 se suffixes-=*.o,*.obj
82 " Vim 5 hardcodes the size of numbers column to 8.
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 " Syntax highlighting. New versions will use syn enable instead.
109 " Use a discernably different colour to highlight the cursor which shows
110 " matching brackets. Our regular cursor is green so use blue instead of cyan.
111 hi MatchParen ctermbg=blue
118 " Set up our variables.
120 if ! exists("b:iainlist")
123 if ! exists("b:iainhex")
126 if ! exists("b:iainverbose")
127 let b:iainverbose = 0
129 if ! exists("b:iainstatus")
130 " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
131 let b:iainstatus = "Fih"
135 " Helper for status line.
136 " Show space, underscore or dollar sign depending on list mode.
142 elseif b:iainlist == 1
151 " Helper for status line.
152 " Show c or C to denote case-sensitivity.
161 " Helper for status line.
162 " Show the size of the tabstop.
167 " Helper for status line.
168 " Show p when paste mode is on.
177 " Show the status line.
178 fun! Show_StatusLine()
180 let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
181 let sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
184 let hexformat='0\x%02B'
187 let sl2=hexformat . '\ \|\ P:%4.6o\ '
191 exec "set statusline=" . sl1 . sl2 . sl3
194 " Toggle case-sensitivity.
199 " Restore window size.
200 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
203 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
204 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
206 " Entering Make mode.
213 fun! MakeMode_unmap()
218 " Show the status line for the first time.
219 call Show_StatusLine()
221 " Function to create mappings with either a hardcoded \ or <Leader>.
222 fun! Mapping(keysequence,mapping)
224 exec "map \\" . a:keysequence . " " . a:mapping
226 exec "map <Leader>" . a:keysequence . " " . a:mapping
230 " Use - and = to create underlines.
231 call Mapping("-", "yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>")
232 call Mapping("=", "yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>")
234 " Change to ts=2 with \2.
235 call Mapping("2", ":se ts=2<CR>:<CR>")
236 " Change to ts=4 with \4.
237 call Mapping("4", ":se ts=4<CR>:<CR>")
238 " Change to ts=8 with \8.
239 call Mapping("8", ":se ts=8<CR>:<CR>")
240 " Change to ts=16 with \6.
241 call Mapping("6", ":se ts=16<CR>:<CR>")
242 " Change to ts=32 with \3.
243 call Mapping("3", ":se ts=32<CR>:<CR>")
244 " Toggle paste mode with \p.
245 call Mapping("p", ":se paste!<CR>:<CR>")
246 " Swap case-sensitivity with \c.
247 call Mapping("c", ":call Invert_Case()<CR>:<CR>")
248 " Change number mode with \n.
249 call Mapping("n", ":se number!<CR>:<CR>")
250 " Expand or shrink window size with \> and \<. For use after toggling number.
251 call Mapping(">", ":exe 'se columns+=' . numberwidth<CR>:<CR>")
252 call Mapping("<", ":exe 'se columns-=' . numberwidth<CR>:<CR>")
253 " Clear search pattern with \/.
254 call Mapping("/", ":let @/=\"\"<CR>:<CR>")
256 " Forget the Ex mode mapping.
259 " Vim tip 99: What's the highlighting group under the cursor?
260 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>")
264 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
265 " Handle options only available in Vim 6 and above.
266 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
270 " Remember quickfix state.
273 " Set indenting by filetype.
276 " Less intrusive syntax highlighting.
280 if has("gui_running")
281 se guifont=DejaVu\ Sans\ Mono\ 10
290 se guifont=DejaVu_Sans_Mono:h10:cANSI
293 " Ignore whitespace when diffing.
294 se diffopt=filler,iwhite
296 " Expand window when doing a vertical diff.
302 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
304 " Remember that we are opening the quickfix window.
305 au BufWinEnter quickfix let g:quickfixing=1
306 au BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
308 " Make * and # work the way you expect in visual mode.
309 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
310 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
314 let basic='tab:\\_,trail:_,extends:<,precedes:>'
316 let b:iainlist = b:iainlist + 1
322 elseif b:iainlist == 1
323 exec "set lcs=" . basic
326 exec "set lcs=" . basic . ",eol:$"
331 " Cycle between hex and decimal display of toolbar stuff.
332 fun! Cycle_HexStatusLine()
334 let b:iainhex = ! b:iainhex
335 call Show_StatusLine()
338 " Cycle verbose display of toolbar stuff.
339 fun! Cycle_VerboseStatusLine()
341 let b:iainverbose = ! b:iainverbose
342 call Show_StatusLine()
345 " Toggle quickfix window.
346 fun! Cycle_Quickfix()
347 if g:quickfixing == 1
355 " Swap hex/decimal statusline with \x.
356 call Mapping("x", ":call Cycle_HexStatusLine()<CR>:<CR>")
357 " Change statusline verbosity with \v.
358 call Mapping("v", ":call Cycle_VerboseStatusLine()<CR>:<CR>")
359 " Cycle list styles with \l.
360 call Mapping("l", ":call Cycle_List()<CR>:<CR>")
361 " Toggle tags with \t.
362 call Mapping("t", ":Tlist<CR>")
363 " Change foldmethod with \f.
364 call Mapping("f", ":se foldenable!<CR>:<CR>")
365 " Toggle quickfix window with \q.
366 call Mapping("q", ":call Cycle_Quickfix()<CR>:<CR>")
367 " Rerun filetype detection with \s. The s is for syntax, as this will be
368 " updated as a side-effect.
369 call Mapping("s", ":filetype detect<CR>:<CR>")
371 " Change status bar colour when various things happen.
372 fun! Highlight_StatusLine(flag)
373 " Get current status.
376 " Change the status based on the flag. XXX: Does Vim let us to do flags?
377 let re = "[" . tolower(a:flag) . toupper(a:flag) . "]"
378 let b:iainstatus = substitute(b:iainstatus, re, a:flag, "")
381 let s:colour = "darkblue"
382 let s:termcolour = ""
383 let s:term88colour = "17"
384 let s:term256colour = "17"
385 " Maybe override depending on status.
386 if b:iainstatus =~# "H"
387 if b:iainstatus =~# "I"
388 " Held in insert mode. Add extra highlight if we don't have focus.
389 if b:iainstatus =~# "f"
390 let s:colour = "darkmagenta"
392 let s:colour = "darkred"
394 let s:term88colour = "32"
395 let s:term256colour = "88"
398 if b:iainstatus =~# "I"
399 " Regular insert mode.
400 let s:colour = "darkred"
401 let s:term88colour = "32"
402 let s:term256colour = "88"
407 let s:termcolour = s:term88colour
409 let s:termcolour = s:term256colour
411 let s:termcolour = s:colour
414 exec "highlight StatusLine guifg=white guibg=" . s:colour . " ctermbg=white ctermfg=" . s:termcolour
417 call Highlight_StatusLine("")
420 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
421 " Handle options only available in Vim 7 and above.
422 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
426 au CursorHoldI * call Highlight_StatusLine("H")
427 au CursorMovedI * call Highlight_StatusLine("h")
428 au FocusGained * call Highlight_StatusLine("F")
429 au FocusLost * call Highlight_StatusLine("f")
430 au InsertEnter * call Highlight_StatusLine("I")
431 au InsertLeave * call Highlight_StatusLine("i")
433 " Make diffs vertical by default.
436 " Set size of numbers column.
439 " Add "previous tab" mapping as gb.