37

If I'm editing two files with vim, changing to the other file ( :bnext, :bprev ) seems to drop the undo history from the open file - hitting the 'u' key reports "Already at oldest change".

For example:

  1. vim testfile1 testfile2
  2. add some stuff to testfile1
  3. :w
  4. :bn
  5. :bp
  6. u
  7. eep! can't undo!

Is there any way to keep this history for non-visible buffers?

3

3 Answers 3

48

The newest version of vim (7.3) has persistent undo, so that you can make a change, close vim completely (even shutdown and restart), restart vim, and undo. In your .vimrc:

" tell it to use an undo file
set undofile
" set a directory to store the undo history
set undodir=/home/yourname/.vimundo/
1
  • 12
    Note that you must create the directory first, vim does not do that automatically. Undo files are saved using the filesystem path (at the same time when saving the file). If you are in /home/peter, then editing .bashrc will create the file /home/peter/.vimundo/%home%peter%.bashrc.
    – Lekensteyn
    Oct 11, 2013 at 17:53
22

Looks like this will do it:

:set hidden

(in .vimrc)

1
1

You can use Viewports.
"vim -o testfile1 testfile2" - open files in splitted window.
":sp filename" - split and open "filename".
":vsp filename" - vertical split and open "filename".
"Ctrl+w+arrow" - Change viewport.

1
  • I'd rather not keep a permanently-visible buffer for each file; it's not unusual to have >20 files open at once. Jul 29, 2010 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.