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
46 " Don't be bugged by messages at the bottom of the screen.
52 " Case-insensitive search.
54 " But override by typing capitals.
57 " Look for ctags in home directory first.
58 se tags=~/.tags,./tags,tags
60 " Use - and = to create underlines.
61 map - yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>
62 map = yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>
64 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
65 " Handle options only available in Vim 5 and above.
66 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
70 " Nuke any pre-existing autocommands.
73 " Save the current window width so we can restore it when we quit.
76 " More GUI options. Add icon, tearoffs and toolbar.
79 " Allow dynamic window resize even if we aren't in an xterm.
80 se t_WS=
\e[8;%p1%d;%p2%dt
82 " Highlight search results.
85 " Syntax highlighting.
93 " Set up our variables.
95 if ! exists("b:iainlist")
98 if ! exists("b:iainhex")
101 if ! exists("b:iainverbose")
102 let b:iainverbose = 0
106 " Helper for status line.
107 " Show space, underscore or dollar sign depending on list mode.
113 elseif b:iainlist == 1
122 " Helper for status line.
123 " Show c or C to denote case-sensitivity.
132 " Helper for status line.
133 " Show the size of the tabstop.
138 " Helper for status line.
139 " Show p when paste mode is on.
148 " Show the status line.
149 fun! Show_StatusLine()
151 let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
152 let sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
155 let hexformat='0\x%02B'
158 let sl2=hexformat . '\ \|\ P:%4.6o\ '
162 exec "set statusline=" . sl1 . sl2 . sl3
165 " Restore window size.
166 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
169 au BufEnter * if &ft == "c" || &ft == "cpp" | call CMode_map() | endif
170 au BufLeave * if &ft == "c" || &ft == "cpp" | call CMode_unmap() | endif
173 au BufEnter * if &ft == "perl" | call PerlMode_map() | endif
174 au BufLeave * if &ft == "perl" | call PerlMode_unmap() | endif
177 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
178 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
182 let oldcinkeys=&cinkeys
183 let oldcinwords=&cinwords
184 set cinkeys=0{,0},:,0#,!^F,o,O,e
185 set cinwords=if,else,while,do,for,switch
190 set cinkeys=oldcinkeys
191 set cinwords=oldcinwords
194 " Entering Perl mode.
196 let oldcinkeys=&cinkeys
197 let oldcinwords=&cinwords
198 set cinkeys=0{,0},:,!^F,o,O,e
199 set cinwords=if,else,while,do,for,eval
203 fun! PerlMode_unmap()
204 set cinkeys=oldcinkeys
205 set cinwords=oldcinwords
208 " Entering Make mode.
215 fun! MakeMode_unmap()
220 " Show the status line for the first time.
221 call Show_StatusLine()
224 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
225 " Handle options only available in Vim 6 and above.
226 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
230 " Track changing number mode.
231 let g:numbercols=&columns
232 let g:numberchanges=0
234 " Less intrusive syntax highlighting.
238 if has("gui_running")
239 se guifont=Bitstream\ Vera\ Sans\ Mono\ 12
243 se guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
246 " Expand window when doing a vertical diff.
251 " Status bar matches the colour.
252 highlight StatusLine guifg=white guibg=blue ctermbg=white ctermfg=blue
255 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
257 " Make * and # work the way you expect in visual mode.
258 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
259 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
263 let basic='tab:\\_,trail:_,extends:<,precedes:>'
265 let b:iainlist = b:iainlist + 1
271 elseif b:iainlist == 1
272 exec "set lcs=" . basic
275 exec "set lcs=" . basic . ",eol:$"
280 " Cycle between hex and decimal display of toolbar stuff.
281 fun! Cycle_HexStatusLine()
283 let b:iainhex = ! b:iainhex
284 call Show_StatusLine()
287 " Cycle verbose display of toolbar stuff.
288 fun! Cycle_VerboseStatusLine()
290 let b:iainverbose = ! b:iainverbose
291 call Show_StatusLine()
294 " Cycle between number mode.
295 " FIXME: Toggling in a split window doesn't work properly. We need to track
296 " the number of windows and number modes. Something for later...
297 " Perhaps have a redraw callback that checks width and original column number.
303 let g:numberchanges=g:numberchanges-1
308 " Change size back if this was the last window.
309 if g:numberchanges == 0
310 let &columns=g:numbercols
315 " Save width between number toggling.
317 " Expand if this was the first change.
318 if g:numberchanges == 0
319 let g:numbercols=&columns
321 " Expand column by our preferred width.
322 let &columns=&columns+&numberwidth
324 " Vim 6 hardcodes width to 8.
325 let &columns=&columns+8
330 let g:numberchanges=g:numberchanges+1
336 " Toggle case-sensitivity.
341 " We'll use Q for various commands. Unmap it.
344 " Change to ts=2 with Q2.
345 map Q2 :se ts=2<CR>:<CR>
346 " Change to ts=4 with Q4.
347 map Q4 :se ts=4<CR>:<CR>
348 " Change to ts=8 with Q8.
349 map Q8 :se ts=8<CR>:<CR>
350 " Change to ts=16 with Q6.
351 map Q6 :se ts=16<CR>:<CR>
352 " Change to ts=32 with Q3.
353 map Q3 :se ts=32<CR>:<CR>
354 " Change foldmethod with Qf.
355 map Qf :se foldenable!<CR>:<CR>
356 " Toggle paste mode with Qp.
357 map Qp :se paste!<CR>:<CR>
358 " Swap hex/decimal statusline with Qx
359 map Qx :call Cycle_HexStatusLine()<CR>:<CR>
360 " Change statusline verbosity with Qv
361 map Qv :call Cycle_VerboseStatusLine()<CR>:<CR>
362 " Swap case-sensitivity with Qc.
363 map Qc :call Invert_Case()<CR>:<CR>
364 " Cycle list styles with Ql.
365 map Ql :call Cycle_List()<CR>:<CR>
366 " Change number mode with Qn.
367 map Qn :call Cycle_Number()<CR>:<CR>
368 " Toggle tags with Qt.
372 fun! PerlMode_unmap()
373 set cinkeys=oldcinkeys
374 set cinwords=oldcinwords
375 set foldmethod=manual
379 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
380 " Handle options only available in Vim 7 and above.
381 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
385 " Set size of numbers column.
388 " Add "previous tab" mapping as gb.