views:

78

answers:

4

Hello everyone, I am a Vim user and sometimes I made several changes in a file but then want to get back to the beginning and have to type :u a lot of times, so I ask you if there is a shortcut to get to the "oldest change"?

Cheers!

Rodrigo Alves Vieira http://rodrigo3n.com | @rodrigo3n

+6  A: 

The keystroke to undo is just u; if you're pressing :u then that's too many keys (although it works, it's four keys instead of one). Usually I would just hold down u and let auto-repeat do the trick (note that Ctrl+R is the opposite of u if you go too far)..

You can reload from the last saved version on disk using :e!.

Greg Hewgill
Good point on using just 'u' instead of ':u'.
Jonathan Leffler
+4  A: 

Does ':e!' (followed by return) work for you? It gets back to the state of the edited file when it was last saved, or when you started if you've not saved yet...

Jonathan Leffler
+2  A: 

Using :e! will get you back to the oldest change as saved. Aside from typing just u instead of :u, also see :h undo-redo for help on all the undo commands.

Other options might be use a vim plugin, such as undo_tags.

msbmsb
+3  A: 

You also have the :earlier command. :help :ea

Benoit
Thanks everyone! All great answers!
rodrigo3n
Interesting - I was not aware of `:earlier` (`:ea`) and `:later` (`:lat`) - thank you.
Jonathan Leffler
Also, you can use their shortenings `g-` and `g+`.
ib