Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undo reloading new buffer with vim

Tags:

vim

I had a file open with gvim and it asked me if I wanted to reload the current buffer because it detected a newer version of the file. I accepted, but it turns out the new buffer is not what I want. Is there a way to recover the old buffer? The file on disk (and the swp file, which I viewed with vim -r) contains the new buffer) unfortunately.

like image 219
Stephen Avatar asked Dec 07 '25 21:12

Stephen


2 Answers

If your buffer had fewer lines than the 'undoreload' settings, then its content will be stored in the undotree just before it was reloaded. This means, that a simple u or g- should get your buffer contents back. A plugin like my histwin plugin or the famous Gundo or undotree plugin could be helpful as well.

Note, this needs a Vim of at least version 7.3 or newer to work. Older Vims didn't store the buffer state on reloading.

like image 107
Christian Brabandt Avatar answered Dec 09 '25 19:12

Christian Brabandt


Try u (undo; if you’ve made changes since reloading, repeat until the old version shows up).

I am in terminal Vim, but I don’t think that should make a difference here. I opened a test file with Vim in one terminal tab, went to a new tab and edited it there, saved that, switched back to the first tab, ran :e to reload the file, and then switched it back to the last version I had opened in the tab with u.

like image 44
Ben Klein Avatar answered Dec 09 '25 19:12

Ben Klein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!