Saturday, November 8, 2014

Re: Limits to undo

AndyHancock wrote:

> What determines whether undo can proceed backward in time
> beyond a certain point? The help pages don't seem to explain
> the above limit.

Mostly the 'undolevel' variable limits undo.

Vim can undo before you saved the file. With persistent
undo, it can even undo to changes before the point when
you started vim. With persistent undo, I can undo changes
that are ~ 2 years old in some files!

I have those undo related settings in my ~/.vimrc:

set undolevels=4000
if exists('+undoreload') | set undoreload=100000 | endif

if has('persistent_undo')
" Make sure that the directory ~/UNDO exists
" for persistent undo to work.
set undodir=~/UNDO
set undofile
endif

" Following mappings allow to cut undo to reduce granularity of
" undos. See also:
" http://vim.wikia.com/wiki/Modified_undo_behavior
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
inoremap <bs> <c-g>u<bs>
inoremap <del> <c-g>u<del>
inoremap <tab> <tab><c-g>u
if version >= 700 && has('autocmd')
" Undo break if I don't press a key in insert mode for a few seconds.
au! CursorHoldI * call feedkeys("\<C-G>u", "nt")
endif

And I highly recommend the undotree plugin by Ming Bai
to view the undotree. Navigating in the undotree
is very confusing without such a plugin. Unlike the other
similar plugin Gundo, undotree is written in pure vim script:

http://www.vim.org/scripts/script.php?script_id=4177

Regards
Dominique

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: