X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.vimrc;h=c2705edf17dd80c72066b73f65cf34f67b0b4e45;hp=9c7457aae5ce398fcc0ae900151f4fab547ba132;hb=3eb908d588d1c1cd6bb5abd1886b9bec4fab701f;hpb=29026c610960a7d96280aa72b4bd0a7394792001 diff --git a/.vimrc b/.vimrc index 9c7457a..c2705ed 100644 --- a/.vimrc +++ b/.vimrc @@ -2,16 +2,16 @@ " Multi-version vimrc compatible with version 4 and above. vim:set fdm=marker: """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Note that "if | call Something() | endif" syntax is unsupported -" in Vim 4 so we write all our functions out the long way. It does work in +" Note that "if | call Something() | endif" syntax is unsupported +" in Vim 4 so we write all our functions out the long way. It does work in " autocommand definitions, however. " Vim 4 complains if version isn't set in the configuration file. version 4.0 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Handle options safe to use in version 4. Vim 4 parses but ignores the -" "if version" syntax used later in this file so we don't use it. No attempt +" Handle options safe to use in version 4. Vim 4 parses but ignores the +" "if version" syntax used later in this file so we don't use it. No attempt " is made to make this configuration compatible with Vim 3. " Some of these settings should strictly be wrapped inside "if has()" blocks " but that would cause them not to be ignored by Vim 4. @@ -67,14 +67,21 @@ se tags=~/.tags,./tags,tags " Don't timeout waiting to interpet, eg, OA as an escape code. se ttimeoutlen=100 +" Remember undo list for closed (but not wiped) buffers. +se hidden + " Use ^B to search backward when completing. inoremap " Use ^L to show matching completions but don't select one. inoremap " Swap jump keys. -noremap ' ` -noremap ` ' +nnoremap ' ` +nnoremap ` ' + +" Select previous widnow. +nnoremap ^ p +nnoremap p "}}}1 " Find stuff. @@ -320,7 +327,7 @@ endfun "}}}2 " Set extra columns depending on window status. fun! Extra_Columns(extra, var, ...) "{{{2 " Vim 6 doesn't have winnr("$"). Determine which windows are open - " ourselves by using :windo to incremement a counter. As Vim 5 + " ourselves by using :windo to incremement a counter. As Vim 5 " doesn't have :windo we require Vim 6 for this. if v:version < "600" return "" @@ -614,6 +621,12 @@ endif "}}}1 if version >= "504" "{{{1 version 5.4 +" Reuse windows when using sbuffer. +se switchbuf=useopen + +" Allow persistent variable saving for localvimrc. +se viminfo+=! + " Do we have Unicode? fun! Has_Unicode() "{{{2 if ! has('multi_byte') @@ -695,7 +708,7 @@ fun! Show_VirtualEdit() "{{{2 if &ve == "all" return "V" - elseif &ve + elseif &ve != '' return "v" else return "" @@ -758,7 +771,7 @@ fun! Show_StatusLine() "{{{2 endif call Iain_Vars() let l:sl1='%2n\:\ %<%1*%f%0*\ [%{Show_List()}%{Show_Bind()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%{Show_VirtualEdit()}%{Show_Undo()}%Y%M%R]%{Show_Alt()}\ ' - let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%0*\ \|\ %P' + let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%V%0*\ \|\ %P' let l:hexformat='%b' if b:iainhex let l:hexformat='0\x%02B' @@ -783,7 +796,7 @@ endif "}}}1 if version >= "600" "{{{1 version 6.0 -if has("gui_win32") +if has("win32") || has("win64") se encoding=utf-8 endif @@ -797,7 +810,14 @@ filetype indent on " Less intrusive syntax highlighting. if has("syntax") - syn enable + " The :syntax enable command tries to source the syntax.vim runtime script. + " Parsing this .vimrc will fail if for some reason the runtime doesn't + " exist, as could be the case if the binary was installed with no support + " files. GNU On Windows is one example of an incomplete installation. + try + syn enable + catch + endtry endif " Set colours. @@ -922,12 +942,30 @@ fun! Cycle_Signs(resize) "{{{2 while strlen(l:signs) let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+') - let l:sign = substitute(l:sign, ':.', "", "") - let l:sign = substitute(l:sign, '=', " texthl=MarkSign text=", "") - let l:sign = substitute(l:sign, '\.', " texthl=MarkDot text=", "") - let l:sign = substitute(l:sign, '-', " texthl=MarkLine linehl=MarkLine text=", "") + let l:name = substitute(l:sign, '[:.=-].*', "", "") + let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "") + let l:ascii = matchstr(l:sign, '^:.') + let l:mark = substitute(l:sign, '^\(:.\)*[.=-]', "", "") + if strlen(l:ascii) + let l:ascii = substitute(l:ascii, '^:', "", "") + let l:ascii = matchstr(l:ascii, '^.') + else + let l:ascii = l:mark + endif + let l:ascii = substitute(l:ascii, '"', '\\"', "") + let l:type = substitute(l:sign, '^:.', "", "") + let l:type = matchstr(l:type, '^.') + + let l:hl = "" + if l:type == "=" + let l:hl = "texthl=MarkSign text=" + elseif l:type == "." + let l:hl = "texthl=MarkDot text=" + elseif l:type == "-" + let l:hl = "texthl=MarkLine text=" + endif - exe "sign define Mark" . l:sign + exe "sign define Mark" . l:name . " " . l:hl . l:mark let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "") endwhile @@ -991,6 +1029,7 @@ fun! Cycle_List() "{{{2 endif call Resize_Columns(Extra_Columns("list", "iainlist", " == 2"), 1) + call Extra_Whitespace_Match() endfun "}}}2 " Cycle between hex and decimal display of toolbar stuff. @@ -1027,6 +1066,11 @@ fun! Cycle_Alt() "{{{2 call Show_StatusLine() endfun "{{{2 +" To be overridden later if applicable. +fun! Extra_Whitespace_Match() "{{{2 + " NOP. +endfun "}}}2 + " Swap hex/decimal statusline with \x. call Mapping("x", ":call Cycle_HexStatusLine():") " Change statusline verbosity with \v. @@ -1051,6 +1095,12 @@ if has("autocmd") endif endif "}}}1 +" move. +nmap MoveLineHalfPageUp +nmap MoveLineHalfPageDown +vmap MoveBlockHalfPageUp +vmap MoveBlockHalfPageDown + """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Handle options only available in Vim 7 and above. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -1225,7 +1275,7 @@ map gb :tabprevious: " Transparency. if has("gui_macvim") se transparency=15 -endif +endif " Yet more GUI options. Add tabs. if has("gui") @@ -1244,6 +1294,58 @@ let g:bufExplorerSplitOutPathName=0 let g:NERDSpaceDelims=1 endif "}}}1 +" localvimrc. +let g:localvimrc_persistent=1 + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Handle options only available in Vim 7.2 and above. +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if version >= "702" "{{{1 +if has("autocmd") + " http://vim.wikia.com/wiki/Highlight_unwanted_spaces + augroup WhitespaceMatch + autocmd! + au Display BufWinEnter * call Extra_Whitespace_Match() + au Display Syntax * call Extra_Whitespace_Match() + au Display BufWinLeave * call clearmatches() + augroup END + + fun! Extra_Whitespace_Match() "{{{2 + " \s\+ + " $ + " \@ + " \%# + let l:pattern = '\s\+\%#\@ + " \(^\s$\) + let l:pattern = '\(^\s$\)\@!' . l:pattern + endif + + let l:hl = 'ctermfg=red guifg=red' + if ! &list + " Underline if we aren't using listchars. + let l:hl = l:hl . ' cterm=underline gui=underline' + endif + highlight clear ExtraWhitespace + exe "highlight ExtraWhitespace " . l:hl + if exists('w:whitespace_match_number') + try + call matchdelete(w:whitespace_match_number) + catch + endtry + call matchadd('ExtraWhitespace', l:pattern, 10, w:whitespace_match_number) + else + let w:whitespace_match_number = matchadd('ExtraWhitespace', l:pattern) + endif + endfun "}}}2 + + call Extra_Whitespace_Match() +endif + +endif "}}}1 + """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Handle options only available in Vim 7.3 and above. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -1255,6 +1357,9 @@ call Mapping("u", ":call Cycle_Undo():") " Remove persistent undo file with \U. call Mapping("U", ":call Clear_Undo():") +" Toggle gundo window with \g. +call Mapping("g", ":call gundo#GundoToggle():") + " Use a persistent undo file if it exists. fun! Check_Undo() "{{{2 if filereadable(undofile(expand("%"))) @@ -1330,6 +1435,12 @@ if has("autocmd") au Display WinEnter * if &diff | se cursorbind | endif endif endif + +" Mapping to reload the gundo window. +if has("autocmd") + au Mode BufEnter * if &ft == "gundo" | try | nnoremap r :call gundo#GundoToggle():call gundo#GundoToggle() | catch | endtry | endif +endif + endif "}}}1 " Resize after startup.