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 " Use - and = to create underlines.
62 map - yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>
63 map = yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>
65 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
66 " Handle options only available in Vim 5 and above.
67 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
71 " Nuke any pre-existing autocommands.
74 " Save the current window width so we can restore it when we quit.
77 " More GUI options. Add icon, tearoffs and toolbar.
80 " Allow dynamic window resize even if we aren't in an xterm.
81 se t_WS=
\e[8;%p1%d;%p2%dt
83 " Highlight search results.
86 " Syntax highlighting.
94 " Set up our variables.
96 if ! exists("b:iainlist")
99 if ! exists("b:iainhex")
102 if ! exists("b:iainverbose")
103 let b:iainverbose = 0
107 " Helper for status line.
108 " Show space, underscore or dollar sign depending on list mode.
114 elseif b:iainlist == 1
123 " Helper for status line.
124 " Show c or C to denote case-sensitivity.
133 " Helper for status line.
134 " Show the size of the tabstop.
139 " Helper for status line.
140 " Show p when paste mode is on.
149 " Show the status line.
150 fun! Show_StatusLine()
152 let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
153 let sl3='L:%4.6l/%-4.6L\ C:%3.6c\ \|\ %P'
156 let hexformat='0\x%02B'
159 let sl2=hexformat . '\ \|\ P:%4.6o\ '
163 exec "set statusline=" . sl1 . sl2 . sl3
166 " Restore window size.
167 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
170 au BufEnter * if &ft == "c" || &ft == "cpp" | call CMode_map() | endif
171 au BufLeave * if &ft == "c" || &ft == "cpp" | call CMode_unmap() | endif
174 au BufEnter * if &ft == "perl" | call PerlMode_map() | endif
175 au BufLeave * if &ft == "perl" | call PerlMode_unmap() | endif
178 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
179 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
183 let oldcinkeys=&cinkeys
184 let oldcinwords=&cinwords
185 set cinkeys=0{,0},:,0#,!^F,o,O,e
186 set cinwords=if,else,while,do,for,switch
191 set cinkeys=oldcinkeys
192 set cinwords=oldcinwords
195 " Entering Perl mode.
197 let oldcinkeys=&cinkeys
198 let oldcinwords=&cinwords
199 set cinkeys=0{,0},:,!^F,o,O,e
200 set cinwords=if,else,while,do,for,eval
204 fun! PerlMode_unmap()
205 set cinkeys=oldcinkeys
206 set cinwords=oldcinwords
209 " Entering Make mode.
216 fun! MakeMode_unmap()
221 " Show the status line for the first time.
222 call Show_StatusLine()
225 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
226 " Handle options only available in Vim 6 and above.
227 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
231 " Track changing number mode.
232 let g:numbercols=&columns
233 let g:numberchanges=0
235 " Less intrusive syntax highlighting.
239 if has("gui_running")
240 se guifont=Bitstream\ Vera\ Sans\ Mono\ 12
244 se guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
247 " Expand window when doing a vertical diff.
252 " Status bar matches the colour.
253 highlight StatusLine guifg=white guibg=blue ctermbg=white ctermfg=blue
256 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
258 " Make * and # work the way you expect in visual mode.
259 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
260 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
264 let basic='tab:\\_,trail:_,extends:<,precedes:>'
266 let b:iainlist = b:iainlist + 1
272 elseif b:iainlist == 1
273 exec "set lcs=" . basic
276 exec "set lcs=" . basic . ",eol:$"
281 " Cycle between hex and decimal display of toolbar stuff.
282 fun! Cycle_HexStatusLine()
284 let b:iainhex = ! b:iainhex
285 call Show_StatusLine()
288 " Cycle verbose display of toolbar stuff.
289 fun! Cycle_VerboseStatusLine()
291 let b:iainverbose = ! b:iainverbose
292 call Show_StatusLine()
295 " Cycle between number mode.
296 " FIXME: Toggling in a split window doesn't work properly. We need to track
297 " the number of windows and number modes. Something for later...
298 " Perhaps have a redraw callback that checks width and original column number.
304 let g:numberchanges=g:numberchanges-1
309 " Change size back if this was the last window.
310 if g:numberchanges == 0
311 let &columns=g:numbercols
316 " Save width between number toggling.
318 " Expand if this was the first change.
319 if g:numberchanges == 0
320 let g:numbercols=&columns
322 " Expand column by our preferred width.
323 let &columns=&columns+&numberwidth
325 " Vim 6 hardcodes width to 8.
326 let &columns=&columns+8
331 let g:numberchanges=g:numberchanges+1
337 " Toggle case-sensitivity.
342 " We'll use Q for various commands. Unmap it.
345 " Change to ts=2 with Q2.
346 map Q2 :se ts=2<CR>:<CR>
347 " Change to ts=4 with Q4.
348 map Q4 :se ts=4<CR>:<CR>
349 " Change to ts=8 with Q8.
350 map Q8 :se ts=8<CR>:<CR>
351 " Change to ts=16 with Q6.
352 map Q6 :se ts=16<CR>:<CR>
353 " Change to ts=32 with Q3.
354 map Q3 :se ts=32<CR>:<CR>
355 " Change foldmethod with Qf.
356 map Qf :se foldenable!<CR>:<CR>
357 " Toggle paste mode with Qp.
358 map Qp :se paste!<CR>:<CR>
359 " Swap hex/decimal statusline with Qx
360 map Qx :call Cycle_HexStatusLine()<CR>:<CR>
361 " Change statusline verbosity with Qv
362 map Qv :call Cycle_VerboseStatusLine()<CR>:<CR>
363 " Swap case-sensitivity with Qc.
364 map Qc :call Invert_Case()<CR>:<CR>
365 " Cycle list styles with Ql.
366 map Ql :call Cycle_List()<CR>:<CR>
367 " Change number mode with Qn.
368 map Qn :call Cycle_Number()<CR>:<CR>
369 " Toggle tags with Qt.
371 " Clear search pattern with Q/.
372 map Q/ :let @/=""<CR>:<CR>
375 fun! PerlMode_unmap()
376 set cinkeys=oldcinkeys
377 set cinwords=oldcinwords
378 set foldmethod=manual
382 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
383 " Handle options only available in Vim 7 and above.
384 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
388 " Set size of numbers column.
391 " Add "previous tab" mapping as gb.