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 " Vim 5 hardcodes the size of numbers column to 8.
74 " Save sessions in UNIX format with / as file separator. This is
78 " Nuke any pre-existing autocommands.
81 " Save the current window width so we can restore it when we quit.
84 " More GUI options. Add icon, tearoffs and toolbar.
87 " Allow dynamic window resize even if we aren't in an xterm.
88 se t_WS=
\e[8;%p1%d;%p2%dt
90 " Highlight search results.
93 " Syntax highlighting.
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
105 " Set up our variables.
107 if ! exists("b:iainlist")
110 if ! exists("b:iainhex")
113 if ! exists("b:iainverbose")
114 let b:iainverbose = 0
118 " Helper for status line.
119 " Show space, underscore or dollar sign depending on list mode.
125 elseif b:iainlist == 1
134 " Helper for status line.
135 " Show c or C to denote case-sensitivity.
144 " Helper for status line.
145 " Show the size of the tabstop.
150 " Helper for status line.
151 " Show p when paste mode is on.
160 " Show the status line.
161 fun! Show_StatusLine()
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'
167 let hexformat='0\x%02B'
170 let sl2=hexformat . '\ \|\ P:%4.6o\ '
174 exec "set statusline=" . sl1 . sl2 . sl3
177 " Toggle case-sensitivity.
182 " Restore window size.
183 au VimLeave * if exists("oldcols") | let &columns=oldcols | endif
186 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
187 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
189 " Entering Make mode.
196 fun! MakeMode_unmap()
201 " Show the status line for the first time.
202 call Show_StatusLine()
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>
228 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
229 " Handle options only available in Vim 6 and above.
230 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
234 " Remember quickfix state.
237 " Set indenting by filetype.
240 " Less intrusive syntax highlighting.
244 if has("gui_running")
245 se guifont=DejaVu\ Sans\ Mono\ 10
249 se guifont=DejaVu_Sans_Mono:h10:cANSI
252 " Ignore whitespace when diffing.
253 se diffopt=filler,iwhite
255 " Expand window when doing a vertical diff.
260 " Status bar matches the colour.
261 highlight StatusLine guifg=white guibg=darkblue ctermbg=white ctermfg=darkblue
264 highlight LineNr term=underline cterm=bold guifg=blue ctermfg=blue
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
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>
276 let basic='tab:\\_,trail:_,extends:<,precedes:>'
278 let b:iainlist = b:iainlist + 1
284 elseif b:iainlist == 1
285 exec "set lcs=" . basic
288 exec "set lcs=" . basic . ",eol:$"
293 " Cycle between hex and decimal display of toolbar stuff.
294 fun! Cycle_HexStatusLine()
296 let b:iainhex = ! b:iainhex
297 call Show_StatusLine()
300 " Cycle verbose display of toolbar stuff.
301 fun! Cycle_VerboseStatusLine()
303 let b:iainverbose = ! b:iainverbose
304 call Show_StatusLine()
307 " Toggle quickfix window.
308 fun! Cycle_Quickfix()
309 if g:quickfixing == 1
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.
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.
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>
341 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
342 " Handle options only available in Vim 7 and above.
343 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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
351 " Make diffs vertical by default.
354 " Set size of numbers column.
357 " Add "previous tab" mapping as gb.