Support new features in Vim 7.3.
authorIain Patterson <me@iain.cx>
Wed, 7 Jul 2010 16:55:19 +0000 (17:55 +0100)
committerIain Patterson <me@iain.cx>
Mon, 19 Jul 2010 12:50:47 +0000 (13:50 +0100)
Enable persistent undo by default if an undofile already exists but not
for temporary files etc.
Show U in the statusline if persistent undo is on.
Show u in the statusline if persistent undo is off but an undofile exists.
Use \u to toggle persistent undo on and off.
Use \U to disable persistent undo and delete the undofile.

Use \CC to toggle ColorColumn at current cursor position.
Use \Cc to remove last set ColorColumn.
Use \Cx to remove all ColorColumns.

.vim/colors/iain.vim
.vimrc

index ef75180..2161f3d 100644 (file)
@@ -266,6 +266,7 @@ if has("gui_running") || &t_Co == 88 || &t_Co == 256
     call <SID>X("DiffText", "#ffffff", "#ff0000", "none")
     call <SID>X("Cursor", "#000000", "#00ff00", "")
     call <SID>X("CursorLine", "", "#2e2e2e", "none")
     call <SID>X("DiffText", "#ffffff", "#ff0000", "none")
     call <SID>X("Cursor", "#000000", "#00ff00", "")
     call <SID>X("CursorLine", "", "#2e2e2e", "none")
+    call <SID>X("ColorColumn", "", "#2e2e2e", "none")
     call <SID>X("lCursor", "#000000", "#ffffff", "")
     "call <SID>X("Comment", "#80a0ff", "", "")
     "call <SID>X("Constant", "#ffa0a0", "", "")
     call <SID>X("lCursor", "#000000", "#ffffff", "")
     "call <SID>X("Comment", "#80a0ff", "", "")
     "call <SID>X("Constant", "#ffa0a0", "", "")
diff --git a/.vimrc b/.vimrc
index b74b7c8..06f749b 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -134,6 +134,8 @@ if has("autocmd")
   endif
   augroup StatusLine
   autocmd!
   endif
   augroup StatusLine
   autocmd!
+  augroup File
+  autocmd!
   augroup END
 endif
 
   augroup END
 endif
 
@@ -662,6 +664,23 @@ fun! Show_Paste() "{{{2
   endif
 endfun "}}}2
 
   endif
 endfun "}}}2
 
+" Helper for status line.
+" Show U when persistent undo is on.
+" Show u when persistent undo is off but an undofile exists.
+fun! Show_Undo() "{{{2
+  if ! exists("&undofile")
+    return ""
+  endif
+
+  if &undofile
+    return "U"
+  elseif filereadable(undofile(expand("%")))
+    return "u"
+  else
+    return ""
+  endif
+endfun "}}}2
+
 " Helper for status line.
 " Show alternate buffer number and name.
 fun! Show_Alt() "{{{2
 " Helper for status line.
 " Show alternate buffer number and name.
 fun! Show_Alt() "{{{2
@@ -679,7 +698,7 @@ fun! Show_StatusLine() "{{{2
     return
   endif
   call Iain_Vars()
     return
   endif
   call Iain_Vars()
-  let l:sl1='%2n\:\ %<%1*%f%0*\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]%{Show_Alt()}\ '
+  let l:sl1='%2n\:\ %<%1*%f%0*\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%{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:hexformat='%b'
   if b:iainhex
   let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%0*\ \|\ %P'
   let l:hexformat='%b'
   if b:iainhex
@@ -1181,6 +1200,90 @@ let g:bufExplorerShowRelativePath=1
 let g:bufExplorerSplitOutPathName=0
 endif "}}}1
 
 let g:bufExplorerSplitOutPathName=0
 endif "}}}1
 
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Handle options only available in Vim 7.3 and above.
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+if version >= "703" "{{{1
+version 7.3
+
+" Toggle persistent undo with \u.
+call Mapping("u", ":call <SID>Cycle_Undo()<CR>:<CR>")
+" Remove persistent undo file with \U.
+call Mapping("U", ":call <SID>Clear_Undo()<CR>:<CR>")
+
+" Use a persistent undo file if it exists.
+fun! <SID>Check_Undo() "{{{2
+  if filereadable(undofile(expand("%")))
+    setlocal undofile
+  endif
+endfun "}}}2
+
+" Toggle persistent undo for this buffer.
+fun! <SID>Cycle_Undo() "{{{2
+  if has("persistent_undo")
+    let &undofile = ! &undofile
+  endif
+endfun "}}}2
+
+" Remove the persistent undo file for this buffer.
+fun! <SID>Clear_Undo() "{{{2
+  if ! has("persistent_undo")
+    return
+  endif
+
+  setlocal noundofile
+
+  let l:f = expand("%")
+  if l:f == ""
+    return
+  endif
+
+  let l:u = undofile(l:f)
+  if l:u == ""
+    return
+  endif
+
+  if ! filereadable(l:u) || ! filewritable(l:u)
+    return
+  endif
+
+  call delete(l:u)
+endfun "}}}2
+
+" Toggle ColorColumn at cursor position.
+fun! <SID>Cycle_ColorColumn() "{{{2
+  if ! has("syntax")
+    return
+  endif
+
+  let l:cc = &colorcolumn
+  let l:column = col(".")
+  let l:re = ",*\\<" . l:column . "\\>"
+  if l:cc =~# l:re
+    let l:cc = substitute(l:cc, l:re, "", "g")
+  else
+    let l:cc = l:cc . "," . l:column
+  endif
+  let &colorcolumn = substitute(l:cc, "^,*", "", "")
+endfun "}}}2
+
+if has("syntax")
+  " Enable showing ColorColumn at cursor position with \CC.
+  call Mapping("CC", ":call <SID>Cycle_ColorColumn()<CR>:<CR>")
+  " Remove last shown ColorColumn with \Cc.
+  call Mapping("Cc", ":let &colorcolumn=substitute(&colorcolumn, \",*[0-9]*$\", \"\", \"\")<CR>:<CR>")
+  " Remove all ColorColumns with \Cx.
+  call Mapping("Cx", ":se colorcolumn=<CR>:<CR>")
+endif
+
+" Use persistent undo if available.
+if has("autocmd")
+  if has("persistent_undo")
+    au File BufReadPost * call <SID>Check_Undo()
+  endif
+endif
+endif "}}}1
+
 " Resize after startup.
 if version >= "500" "{{{1
 if has("autocmd")
 " Resize after startup.
 if version >= "500" "{{{1
 if has("autocmd")