Added initial conversion of darkblue for terminal.
[profile.git] / .vimrc
1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 " $Id$
3 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4 " Multi-version vimrc compatible with version 4 and above.
5 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6
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.
10
11 " Vim 4 complains if version isn't set in the configuration file.
12 version 4.0
13
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.
20 se nocp
21
22 " Tabstop 2.
23 se ts=2
24 " And use spaces not tabs.
25 se expandtab
26 " And << and >> indent by 2.
27 se sw=2
28
29 " Allow backspace to delete before start of line.
30 se bs=2
31
32 " Show the ruler.
33 se ruler
34 " Show partial commands in the ruler.
35 se showcmd
36 " And always show the status line.
37 se laststatus=2
38
39 " Use C indent style.
40 se cindent
41 se cinkeys=0{,0},0),:,!^F,o,O,e
42 se cinoptions=b1,c2
43
44 " GUI options.
45 se go=aglmr
46
47 " Don't be bugged by messages at the bottom of the screen.
48 se shm=aot
49
50 " Find as you type.
51 se incsearch
52
53 " Case-insensitive search.
54 se ignorecase
55 " But override by typing capitals.
56 se smartcase
57
58 " Look for ctags in home directory first.
59 se tags=~/.tags,./tags,tags
60
61 " Don't timeout waiting to interpet, eg, <ESC>OA as an escape code.
62 se ttimeoutlen=100
63
64 " Use - and = to create underlines.
65 map - yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>
66 map = yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>
67
68 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
69 " Handle options only available in Vim 5 and above.
70 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
71 if version >= "500"
72 version 5.0
73
74 " Tell Vim we use dark backgrounds in our terminals.
75 if ! has("gui_running")
76   se bg=dark
77 endif
78
79 " Vim 5 hardcodes the size of numbers column to 8.
80 let numberwidth=8
81
82 " Save sessions in UNIX format with / as file separator.  This is
83 " cross-platoform.
84 se ssop+=unix,slash
85
86 " Nuke any pre-existing autocommands.
87 autocmd!
88
89 " Save the current window width so we can restore it when we quit.
90 let oldcols=&columns
91
92 " More GUI options.  Add icon, tearoffs and toolbar.
93 se go+=itT
94
95 " Allow dynamic window resize even if we aren't in an xterm.
96 se t_WS=\e[8;%p1%d;%p2%dt
97
98 " Highlight search results.
99 se hlsearch
100
101 " Syntax highlighting.
102 syn on
103
104 " Use a discernably different colour to highlight the cursor which shows 
105 " matching brackets.  Our regular cursor is green so use blue instead of cyan.
106 hi MatchParen ctermbg=blue
107
108 " Catch typos.
109 command! W :w
110 command! Wq :wq
111 command! Wqa :wqa
112
113 " Set up our variables.
114 fun! Iain_Vars()
115   if ! exists("b:iainlist")
116     let b:iainlist = 0
117   endif
118   if ! exists("b:iainhex")
119     let b:iainhex = 0
120   endif
121   if ! exists("b:iainverbose")
122     let b:iainverbose = 0
123   endif
124   if ! exists("b:iainstatus")
125     " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old.
126     let b:iainstatus = "Fih"
127   endif
128 endfun
129
130 " Helper for status line.
131 " Show space, underscore or dollar sign depending on list mode.
132 fun! Show_List()
133   call Iain_Vars()
134   if b:iainlist == 0
135     " No list.
136     return " "
137   elseif b:iainlist == 1
138     " Just tabs.
139     return "_"
140   else
141     " Full list.
142     return "\$"
143   endif
144 endfun
145
146 " Helper for status line.
147 " Show c or C to denote case-sensitivity.
148 fun! Show_Case()
149   if &ic
150     return "c"
151   else
152     return "C"
153   endif
154 endfun
155
156 " Helper for status line.
157 " Show the size of the tabstop.
158 fun! Show_Tabstop()
159   return &ts
160 endfun
161
162 " Helper for status line.
163 " Show p when paste mode is on.
164 fun! Show_Paste()
165   if &paste
166     return "p"
167   else
168     return ""
169   endif
170 endfun
171
172 " Show the status line.
173 fun! Show_StatusLine()
174   call Iain_Vars()
175   let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
176   let sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
177   let hexformat='%b'
178   if b:iainhex
179     let hexformat='0\x%02B'
180   endif
181   if b:iainverbose
182     let sl2=hexformat . '\ \|\ P:%4.6o\ '
183   else
184     let sl2=''
185   endif
186   exec "set statusline=" . sl1 . sl2 . sl3
187 endfun
188
189 " Toggle case-sensitivity.
190 fun! Invert_Case()
191   let &ic = ! &ic
192 endfun
193
194 " Restore window size.
195 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
196
197 " Map Makefile mode.
198 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
199 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
200
201 " Entering Make mode.
202 fun! MakeMode_map()
203   set list
204   set noexpandtab
205 endfun
206
207 " Leaving Make mode.
208 fun! MakeMode_unmap()
209   set nolist
210   set expandtab
211 endfun
212
213 " Show the status line for the first time.
214 call Show_StatusLine()
215
216 " Change to ts=2 with Q2.
217 map Q2 :se ts=2<CR>:<CR>
218 " Change to ts=4 with Q4.
219 map Q4 :se ts=4<CR>:<CR>
220 " Change to ts=8 with Q8.
221 map Q8 :se ts=8<CR>:<CR>
222 " Change to ts=16 with Q6.
223 map Q6 :se ts=16<CR>:<CR>
224 " Change to ts=32 with Q3.
225 map Q3 :se ts=32<CR>:<CR>
226 " Toggle paste mode with Qp.
227 map Qp :se paste!<CR>:<CR>
228 " Swap case-sensitivity with Qc.
229 map Qc :call Invert_Case()<CR>:<CR>
230 " Change number mode with Qn.
231 map Qn :se number!<CR>:<CR>
232 " Expand or shrink window size with Q> and Q<.  For use after toggling number.
233 map Q> :exe 'se columns+=' . numberwidth<CR>:<CR>
234 map Q< :exe 'se columns-=' . numberwidth<CR>:<CR>
235 " Clear search pattern with Q/.
236 map Q/ :let @/=""<CR>:<CR>
237
238 endif
239
240 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
241 " Handle options only available in Vim 6 and above.
242 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
243 if version >= "600"
244 version 6.0
245
246 " Remember quickfix state.
247 let g:quickfixing=0
248
249 " Set indenting by filetype.
250 filetype indent on
251
252 " Less intrusive syntax highlighting.
253 syn enable
254
255 " Nice GUI colour.
256 if has("gui_running")
257   se guifont=DejaVu\ Sans\ Mono\ 10
258   colo darkblue
259 endif
260 if has("win32")
261   se guifont=DejaVu_Sans_Mono:h10:cANSI
262 endif
263
264 " Ignore whitespace when diffing.
265 se diffopt=filler,iwhite
266
267 " Expand window when doing a vertical diff.
268 if &diff
269   let &columns = 164
270 endif
271
272 " Status bar matches the colour.
273 highlight StatusLine guifg=white guibg=darkblue ctermbg=white ctermfg=darkblue
274
275 " Numbers in blue.
276 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
277
278 " Remember that we are opening the quickfix window.
279 au BufWinEnter quickfix let g:quickfixing=1
280 au BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
281
282 " Make * and # work the way you expect in visual mode.
283 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
284 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
285
286 " Change list mode.
287 fun! Cycle_List()
288   let basic='tab:\\_,trail:_,extends:<,precedes:>'
289   call Iain_Vars()
290   let b:iainlist = b:iainlist + 1
291   if b:iainlist > 2
292     let b:iainlist = 0
293   endif
294   if b:iainlist == 0
295     set nolist
296   elseif b:iainlist == 1
297     exec "set lcs=" . basic
298     set list
299   else
300     exec "set lcs=" . basic . ",eol:$"
301     set list
302   endif
303 endfun
304
305 " Cycle between hex and decimal display of toolbar stuff.
306 fun! Cycle_HexStatusLine()
307   call Iain_Vars()
308   let b:iainhex = ! b:iainhex
309   call Show_StatusLine()
310 endfun
311
312 " Cycle verbose display of toolbar stuff.
313 fun! Cycle_VerboseStatusLine()
314   call Iain_Vars()
315   let b:iainverbose = ! b:iainverbose
316   call Show_StatusLine()
317 endfun
318
319 " Toggle quickfix window.
320 fun! Cycle_Quickfix()
321   if g:quickfixing == 1
322     cclose
323     let g:quickfixing=0
324   else
325     copen
326   endif
327 endfun
328
329 " We use Q for various commands.  Unmap it.
330 " Vim 5 won't let us unmap this as it treats Q as an ambiguous mapping (because 
331 " Qx also exists.  With Vim 5 you are rewarded with Ex mode if you don't type 
332 " the Qx sequence quickly enough.  Vim 6 allows us to forget the Ex mapping.
333 map Q <Nop>
334
335 " Swap hex/decimal statusline with Qx.
336 map Qx :call Cycle_HexStatusLine()<CR>:<CR>
337 " Change statusline verbosity with Qv.
338 map Qv :call Cycle_VerboseStatusLine()<CR>:<CR>
339 " Cycle list styles with Ql.
340 map Ql :call Cycle_List()<CR>:<CR>
341 " Toggle tags with Qt.
342 map Qt :Tlist<CR>
343 " Change foldmethod with Qf.
344 map Qf :se foldenable!<CR>:<CR>
345 " Toggle quickfix window with Qq.
346 map Qq :call Cycle_Quickfix()<CR>:<CR>
347 " Rerun filetype detection with Qs.  The s is for syntax, as this will be
348 " updated as a side-effect.
349 map Qs :filetype detect<CR>:<CR>
350
351 endif
352
353 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
354 " Handle options only available in Vim 7 and above.
355 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
356 if version >= "700"
357 version 7.0
358
359 " Change status bar colour when entering insert mode.
360 fun! Highlight_StatusLine(flag)
361   " Get current status.
362   call Iain_Vars()
363
364   " Change the status based on the flag.  XXX: Does Vim let us to do flags?
365   let re = "[" . tolower(a:flag) . toupper(a:flag) . "]"
366   let b:iainstatus = substitute(b:iainstatus, re, a:flag, "")
367
368   " Default colour.
369   let colour = "darkblue"
370   " Maybe override depending on status.
371   if b:iainstatus =~# "H"
372     if b:iainstatus =~# "I"
373       " Held in insert mode.  Add extra highlight if we don't have focus.
374       if b:iainstatus =~# "f"
375         let colour = "darkmagenta"
376       else
377         let colour = "darkred"
378       endif
379     endif
380   else
381     if b:iainstatus =~# "I"
382       " Regular insert mode.
383       let colour = "darkred"
384     endif
385   endif
386
387   exec "highlight StatusLine guifg=white guibg=" . colour . " ctermbg=white ctermfg=" . colour
388 endfun
389
390 au CursorHoldI * call Highlight_StatusLine("H")
391 au CursorMovedI * call Highlight_StatusLine("h")
392 au FocusGained * call Highlight_StatusLine("F")
393 au FocusLost * call Highlight_StatusLine("f")
394 au InsertEnter * call Highlight_StatusLine("I")
395 au InsertLeave * call Highlight_StatusLine("i")
396
397 " Make diffs vertical by default.
398 se diffopt+=vertical
399
400 " Set size of numbers column.
401 se numberwidth=5
402
403 " Add "previous tab" mapping as gb.
404 map gb :tabPrev<CR>
405 endif