Use DejaVu font.
[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 " Use - and = to create underlines.
62 map - yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>
63 map = yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>
64
65 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
66 " Handle options only available in Vim 5 and above.
67 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
68 if version >= "500"
69 version 5.0
70
71 " Vim 5 hardcodes the size of numbers column to 8.
72 let numberwidth=8
73
74 " Save sessions in UNIX format with / as file separator.  This is
75 " cross-platoform.
76 se ssop+=unix,slash
77
78 " Nuke any pre-existing autocommands.
79 autocmd!
80
81 " Save the current window width so we can restore it when we quit.
82 let oldcols=&columns
83
84 " More GUI options.  Add icon, tearoffs and toolbar.
85 se go+=itT
86
87 " Allow dynamic window resize even if we aren't in an xterm.
88 se t_WS=\e[8;%p1%d;%p2%dt
89
90 " Highlight search results.
91 se hlsearch
92
93 " Syntax highlighting.
94 syn on
95
96 " Use a discernably different colour to highlight the cursor which shows 
97 " matching brackets.  Our regular cursor is green so use blue instead of cyan.
98 hi MatchParen ctermbg=blue
99
100 " Catch typos.
101 command! W :w
102 command! Wq :wq
103 command! Wqa :wqa
104
105 " Set up our variables.
106 fun! Iain_Vars()
107   if ! exists("b:iainlist")
108     let b:iainlist = 0
109   endif
110   if ! exists("b:iainhex")
111     let b:iainhex = 0
112   endif
113   if ! exists("b:iainverbose")
114     let b:iainverbose = 0
115   endif
116 endfun
117
118 " Helper for status line.
119 " Show space, underscore or dollar sign depending on list mode.
120 fun! Show_List()
121   call Iain_Vars()
122   if b:iainlist == 0
123     " No list.
124     return " "
125   elseif b:iainlist == 1
126     " Just tabs.
127     return "_"
128   else
129     " Full list.
130     return "\$"
131   endif
132 endfun
133
134 " Helper for status line.
135 " Show c or C to denote case-sensitivity.
136 fun! Show_Case()
137   if &ic
138     return "c"
139   else
140     return "C"
141   endif
142 endfun
143
144 " Helper for status line.
145 " Show the size of the tabstop.
146 fun! Show_Tabstop()
147   return &ts
148 endfun
149
150 " Helper for status line.
151 " Show p when paste mode is on.
152 fun! Show_Paste()
153   if &paste
154     return "p"
155   else
156     return ""
157   endif
158 endfun
159
160 " Show the status line.
161 fun! Show_StatusLine()
162   call Iain_Vars()
163   let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
164   let sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
165   let hexformat='%b'
166   if b:iainhex
167     let hexformat='0\x%02B'
168   endif
169   if b:iainverbose
170     let sl2=hexformat . '\ \|\ P:%4.6o\ '
171   else
172     let sl2=''
173   endif
174   exec "set statusline=" . sl1 . sl2 . sl3
175 endfun
176
177 " Toggle case-sensitivity.
178 fun! Invert_Case()
179   let &ic = ! &ic
180 endfun
181
182 " Restore window size.
183 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
184
185 " Map Makefile mode.
186 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
187 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
188
189 " Entering Make mode.
190 fun! MakeMode_map()
191   set list
192   set noexpandtab
193 endfun
194
195 " Leaving Make mode.
196 fun! MakeMode_unmap()
197   set nolist
198   set expandtab
199 endfun
200
201 " Show the status line for the first time.
202 call Show_StatusLine()
203
204 " Change to ts=2 with Q2.
205 map Q2 :se ts=2<CR>:<CR>
206 " Change to ts=4 with Q4.
207 map Q4 :se ts=4<CR>:<CR>
208 " Change to ts=8 with Q8.
209 map Q8 :se ts=8<CR>:<CR>
210 " Change to ts=16 with Q6.
211 map Q6 :se ts=16<CR>:<CR>
212 " Change to ts=32 with Q3.
213 map Q3 :se ts=32<CR>:<CR>
214 " Toggle paste mode with Qp.
215 map Qp :se paste!<CR>:<CR>
216 " Swap case-sensitivity with Qc.
217 map Qc :call Invert_Case()<CR>:<CR>
218 " Change number mode with Qn.
219 map Qn :se number!<CR>:<CR>
220 " Expand or shrink window size with Q> and Q<.  For use after toggling number.
221 map Q> :exe 'se columns+=' . numberwidth<CR>:<CR>
222 map Q< :exe 'se columns-=' . numberwidth<CR>:<CR>
223 " Clear search pattern with Q/.
224 map Q/ :let @/=""<CR>:<CR>
225
226 endif
227
228 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
229 " Handle options only available in Vim 6 and above.
230 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
231 if version >= "600"
232 version 6.0
233
234 " Remember quickfix state.
235 let g:quickfixing=0
236
237 " Set indenting by filetype.
238 filetype indent on
239
240 " Less intrusive syntax highlighting.
241 syn enable
242
243 " Nice GUI colour.
244 if has("gui_running")
245   se guifont=DejaVu\ Sans\ Mono\ 10
246   colo darkblue
247 endif
248 if has("win32")
249   se guifont=DejaVu_Sans_Mono:h10:cANSI
250 endif
251
252 " Ignore whitespace when diffing.
253 se diffopt=filler,iwhite
254
255 " Expand window when doing a vertical diff.
256 if &diff
257   let &columns = 164
258 endif
259
260 " Status bar matches the colour.
261 highlight StatusLine guifg=white guibg=darkblue ctermbg=white ctermfg=darkblue
262
263 " Numbers in blue.
264 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
265
266 " Remember that we are opening the quickfix window.
267 au BufWinEnter quickfix let g:quickfixing=1
268 au BufUnload * if &ft == "qf" | let g:quickfixing=0 | endif
269
270 " Make * and # work the way you expect in visual mode.
271 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
272 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
273
274 " Change list mode.
275 fun! Cycle_List()
276   let basic='tab:\\_,trail:_,extends:<,precedes:>'
277   call Iain_Vars()
278   let b:iainlist = b:iainlist + 1
279   if b:iainlist > 2
280     let b:iainlist = 0
281   endif
282   if b:iainlist == 0
283     set nolist
284   elseif b:iainlist == 1
285     exec "set lcs=" . basic
286     set list
287   else
288     exec "set lcs=" . basic . ",eol:$"
289     set list
290   endif
291 endfun
292
293 " Cycle between hex and decimal display of toolbar stuff.
294 fun! Cycle_HexStatusLine()
295   call Iain_Vars()
296   let b:iainhex = ! b:iainhex
297   call Show_StatusLine()
298 endfun
299
300 " Cycle verbose display of toolbar stuff.
301 fun! Cycle_VerboseStatusLine()
302   call Iain_Vars()
303   let b:iainverbose = ! b:iainverbose
304   call Show_StatusLine()
305 endfun
306
307 " Toggle quickfix window.
308 fun! Cycle_Quickfix()
309   if g:quickfixing == 1
310     cclose
311     let g:quickfixing=0
312   else
313     copen
314   endif
315 endfun
316
317 " We use Q for various commands.  Unmap it.
318 " Vim 5 won't let us unmap this as it treats Q as an ambiguous mapping (because 
319 " Qx also exists.  With Vim 5 you are rewarded with Ex mode if you don't type 
320 " the Qx sequence quickly enough.  Vim 6 allows us to forget the Ex mapping.
321 map Q <Nop>
322
323 " Swap hex/decimal statusline with Qx.
324 map Qx :call Cycle_HexStatusLine()<CR>:<CR>
325 " Change statusline verbosity with Qv.
326 map Qv :call Cycle_VerboseStatusLine()<CR>:<CR>
327 " Cycle list styles with Ql.
328 map Ql :call Cycle_List()<CR>:<CR>
329 " Toggle tags with Qt.
330 map Qt :Tlist<CR>
331 " Change foldmethod with Qf.
332 map Qf :se foldenable!<CR>:<CR>
333 " Toggle quickfix window with Qq.
334 map Qq :call Cycle_Quickfix()<CR>:<CR>
335 " Rerun filetype detection with Qs.  The s is for syntax, as this will be
336 " updated as a side-effect.
337 map Qs :filetype detect<CR>:<CR>
338
339 endif
340
341 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
342 " Handle options only available in Vim 7 and above.
343 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
344 if version >= "700"
345 version 7.0
346
347 " Change status bar colour when entering insert mode.
348 au InsertEnter * highlight StatusLine guifg=white guibg=darkred ctermbg=white ctermfg=darkred
349 au InsertLeave * highlight StatusLine guifg=white guibg=blue ctermbg=white ctermfg=blue
350
351 " Make diffs vertical by default.
352 se diffopt+=vertical
353
354 " Set size of numbers column.
355 se numberwidth=5
356
357 " Add "previous tab" mapping as gb.
358 map gb :tabPrev<CR>
359 endif