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?

  • should this be in superuser or stackoverflow instead?
    – Ressu
    Commented Jul 29, 2010 at 8:32
  • @Ressu - good point, how do we tell? Meta question posted: meta.ubuntu.stackexchange.com/questions/47/… Commented Jul 29, 2010 at 8:45
  • Depending on the outcome of that meta question, I'm likely to delete this. Commented Jul 29, 2010 at 9:24

3 Answers 3


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/
  • 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
    Commented Oct 11, 2013 at 17:53

Looks like this will do it:

:set hidden

(in .vimrc)


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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .