Sunday, November 9, 2014

Re: Limits to undo

On Saturday, November 8, 2014 9:35:12 PM UTC-6, AndyHancock wrote:
> I have undolevels set to 1000, which is easily exceeded if each keystroke is a count of 1.
>
> Sigh.
>
> I will look into persistence. I thank you for the educational material in your post.

Actually each keystroke is definitely NOT a count of 1. If you type "d3w" to delete 3 words, that's a single change. If you type "aHello world! I'm writing text!<Esc>" to insert two sentences, that's still only one change in terms of undolevels.

You *may* be reaching 1000 changes, in which case you can always set undolevels higher in your .vimrc.

But more likely, you're hitting one of these scenarios:
* You don't have persistent undo turned on
* The file was modified outside of Vim
* You overwrote the file from Vim with a :w! or :saveas! when you were editing a different file
* You reloaded the file in Vim and it is a big file

In the first case, just put "set undofile" in your .vimrc. If you do this, Vim saves the current undo tree to a file when exiting, and reloads it the next time you edit that file.

In the second case, even if persistent undo is turned on, Vim will not have undo information for the file. Undo files are only used if the file contents match what they were when the undo file was created.

The third case is a special case of the undo file not matching, so the original file's saved undo tree will not work. And the new undo tree applies to the buffer you've been editing, not the original file, so that also won't work.

In the final case, Vim can discard the undo tree when you reload a file (for example using ":e!" to discard changes instead of ":earlier 1f"). But, Vim will add the reload to the undo tree as long as the file is short enough. You can change what "short enough" means using the 'undoreload' option (default 10000 lines).

--
--
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: