X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.vimrc;h=3f4fd1df05b2c62d08eef020213bd6eea7946c21;hp=15a641406b7494a2e0cc4c95ae504446df19f3e2;hb=24b96a93258908176503c7e6d9c4c0b912f87b2b;hpb=91f4c218cbcf1e754011dc4b2ed89569407d63c4 diff --git a/.vimrc b/.vimrc index 15a6414..3f4fd1d 100644 --- a/.vimrc +++ b/.vimrc @@ -75,12 +75,16 @@ if ! has("gui_running") se bg=dark endif -" Allow mouse use in a terminal. -se mouse=nvir +" Allow mouse use in a terminal but only if it can work. +if has("xterm_clipboard") + se mouse=nvir +endif " Update more quickly. For use with sign highlighting as polling for " CursorMove makes redrawing slow. -se updatetime=500 +if has("signs") + se updatetime=500 +endif " Enable tab-completion prompting for commands. se wildmenu @@ -98,19 +102,22 @@ augroup Display autocmd! augroup Mode autocmd! -augroup Signs -autocmd! +if has("signs") + augroup Signs + autocmd! +endif augroup StatusLine autocmd! augroup END " Save the current window width so we can restore it when we quit. -if ! exists("oldcols") - let oldcols=&columns +if ! exists("g:oldcols") + let g:oldcols=&columns endif -" More GUI options. Add icon, tearoffs and toolbar. -se go+=itT +" More GUI options. Add icon and tearoffs. +se go+=i +se go+=t " Allow dynamic window resize even if we aren't in an xterm. se t_WS=[8;%p1%d;%p2%dt @@ -126,10 +133,6 @@ if version < "600" syn on endif -" Use a discernably different colour to highlight the cursor which shows -" matching brackets. Our regular cursor is green so use blue instead of cyan. -hi MatchParen ctermbg=blue - " Catch typos. command! W :w command! Wq :wq @@ -153,11 +156,13 @@ fun! Iain_Vars() if ! exists("g:iainextracolumns") let g:iainextracolumns = 0 endif - if ! exists("g:marksigns") - let g:marksigns = 0 - endif - if ! exists("g:firstsign") - let g:firstsign = 100 + if has("signs") + if ! exists("g:marksigns") + let g:marksigns = 0 + endif + if ! exists("g:firstsign") + let g:firstsign = 100 + endif endif endfun @@ -248,7 +253,8 @@ fun! Resize_Columns(op, ...) let l:columns = a:1 endif - let l:resize = "se columns" . a:op . "=" . l:columns + exe "let l:resize=" . &columns . a:op . l:columns + let l:resize = "se columns=" . l:resize " HACK: Inside screen there is an extra line for the status bar. Vim " manages the resize by sending an escape sequence to set the number of @@ -258,14 +264,14 @@ fun! Resize_Columns(op, ...) " the real terminal being shrunk by a line. We ask for the terminal to grow " by a line so it ends up actually being the same. if &term =~ '^screen' - let l:resize .= " lines+=1" + let l:resize = l:resize . " lines=" . (&lines + 1) endif - exec l:resize + exe l:resize endfun " Toggle number display. -fun! Number() +fun! Number(resize) call Iain_Vars() let &number = ! &number @@ -281,16 +287,20 @@ fun! Number() if l:num_numbers == 0 let g:iainextracolumns = 0 - call Resize_Columns("-") + if a:resize + call Resize_Columns("-") + endif elseif g:iainextracolumns == 0 let g:iainextracolumns = 1 - call Resize_Columns("+") + if a:resize + call Resize_Columns("+") + endif endif endif endfun " Restore window size. -au Display VimLeave * if exists("oldcols") | let &columns=oldcols | endif +au Display VimLeave * if exists("g:oldcols") | call Resize_Columns("-", (&columns - g:oldcols)) | endif " Map Makefile mode. au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif @@ -343,7 +353,7 @@ call Mapping("p", ":se paste!:") " Swap case-sensitivity with \c. call Mapping("c", ":call Invert_Case():") " Change number mode with \n. -call Mapping("n", ":call Number():") +call Mapping("n", ":call Number(1):") " Expand or shrink window size with \> and \<. call Mapping(">", ":call Resize_Columns('+'):") call Mapping("<", ":call Resize_Columns('-'):") @@ -356,8 +366,62 @@ map Q " Vim tip 99: What's the highlighting group under the cursor? call Mapping("h", ":echo \"hi<\" . synIDattr(synID(line(\".\"),col(\".\"),1),\"name\") . '> trans<' . synIDattr(synID(line(\".\"),col(\".\"),0),\"name\") . \"> lo<\" . synIDattr(synIDtrans(synID(line(\".\"),col(\".\"),1)),\"name\") . \">\"") +fun! Uncluttered_Buffer() + if exists("uncluttered_buffer") + if uncluttered_buffer == 1 + return 1 + endif + endif + + if version >= "600" + if &buftype != '' + return 1 + endif + endif + + if &ft == 'perforce' + return 1 + endif + + if &ft == 'svn' + return 1 + endif + + if &ft == 'gitcommit' + return 1 + endif + + return 0 +endfun + +fun! Startup_Resize() + let l:columns = 0 + + " Resize for numbers. + if &number + if version >= "700" + let l:columns = &numberwidth + else + let l:columns = 8 + endif + endif + + " Resize for signs. + if has("signs") + if g:marksigns + if version >= "600" + let l:columns = l:columns + 2 + endif + endif + endif + + if g:oldcols < (80 + l:columns) + call Resize_Columns("+", l:columns) + endif +endfun + " Show numbers by default. -au Display VimEnter * call Number() +au Display VimEnter * if ! Uncluttered_Buffer() | call Number(0) | endif endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -375,28 +439,23 @@ filetype indent on " Less intrusive syntax highlighting. syn enable -" Nice GUI colour. +" Set colours. if has("gui_running") - se guifont=DejaVu\ Sans\ Mono\ 10 - " XXX: Sort this out. - colo darkblue - hi Cursor guibg=green - hi LineNr guibg=#303030 - hi MarkLine guibg=#2e2e2e - hi MarkDot guifg=red guibg=#2e2e2e - hi MarkSign guifg=lightblue guibg=#2e2e2e - hi! link SignColumn LineNr -elseif &t_Co > 16 try - colo iain + if has("win32") + se guifont=DejaVu_Sans_Mono:h10:cANSI + else + se guifont=DejaVu\ Sans\ Mono\ 10 + endif catch endtry endif -if has("win32") - se guifont=DejaVu_Sans_Mono:h10:cANSI +if has("gui_running") || &t_Co > 16 + try + colo iain + catch + endtry endif -hi! link TabLineSel StatusLine -hi! link TabLine StatusLineNC " Ignore whitespace when diffing. se diffopt=filler,iwhite @@ -418,8 +477,10 @@ vnoremap * y/\V=substitute(escape(@@,"/\\"),"\n","\\\\n","ge") vnoremap # y?\V=substitute(escape(@@,"?\\"),"\n","\\\\n","ge") " Set mark and update highlighting. -au Signs BufEnter * call Highlight_Signs() -au Signs CursorHold * call Highlight_Signs() +if has("signs") + au Signs BufEnter * call Highlight_Signs() + au Signs CursorHold * call Highlight_Signs() +endif fun! Prep_Signs() if ! exists("b:signdot") || ! g:marksigns @@ -496,7 +557,7 @@ fun! Place_Sign(number, line, old, name) endfun fun! Highlight_Signs(...) - if ! g:marksigns + if ! has("signs") || ! g:marksigns || Uncluttered_Buffer() return endif @@ -526,7 +587,10 @@ fun! Highlight_Signs(...) endfun " Toggle signs. -fun! Cycle_Signs() +fun! Cycle_Signs(resize) + if ! has("signs") + return + endif call Iain_Vars() let g:marksigns = ! g:marksigns @@ -554,7 +618,9 @@ fun! Cycle_Signs() sign define MarkE text=E texthl=MarkSign linehl=MarkLine sign define MarkF text=F texthl=MarkSign linehl=MarkLine - call Resize_Columns("+", 2) + if a:resize + call Resize_Columns("+", 2) + endif call Highlight_Signs() else exe "sign unplace " . (g:firstsign + 0) @@ -600,7 +666,9 @@ fun! Cycle_Signs() sign undefine MarkF call Prep_Signs() - call Resize_Columns("-", 2) + if a:resize + call Resize_Columns("-", 2) + endif endif endfun @@ -663,7 +731,7 @@ call Mapping("q", ":call Cycle_Quickfix():") " updated as a side-effect. call Mapping("s", ":filetype detect:") " Toggle marks with \m. -call Mapping("m", ":call Cycle_Signs():") +call Mapping("m", ":call Cycle_Signs(1):") fun! Iain_Colour(colour) if &t_Co == 88 @@ -736,13 +804,13 @@ fun! Highlight_StatusLine(flag) let l:termcolour = Iain_Colour(l:colour) - exec "highlight StatusLine guifg=white guibg=" . l:colour . " ctermbg=white ctermfg=" . l:termcolour + exec "highlight StatusLine gui=bold term=bold cterm=bold guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour endfun au Display VimEnter * call Highlight_StatusLine("") " Show signs by default. -au Display VimEnter * call Cycle_Signs() +au Display VimEnter * call Cycle_Signs(0) endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -771,7 +839,7 @@ endfun " Find out if any buffer was modified. fun! TabModified(buflist) let l:i = 0 - while i < len(a:buflist) + while l:i < len(a:buflist) if getbufvar(a:buflist[l:i], "&modified") == 1 return "+" endif @@ -829,8 +897,10 @@ au StatusLine FocusLost * call Highlight_StatusLine("f") au StatusLine InsertEnter * call Highlight_StatusLine("I") au StatusLine InsertLeave * call Highlight_StatusLine("i") -au Signs InsertEnter * call Highlight_Signs() -au Signs InsertLeave * call Highlight_Signs() +if has("signs") + au Signs InsertEnter * call Highlight_Signs() + au Signs InsertLeave * call Highlight_Signs() +endif " Limit the size of the popup menu when completing. se pumheight=20 @@ -856,3 +926,8 @@ se go+=e let g:p4EnableMenu=1 let g:p4Presets='P4CONFIG' endif + +if version >= "500" +" Resize after startup. +au Display VimEnter * call Startup_Resize() +endif