Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
should this be in superuser or stackoverflow instead? – Ressu Jul 29 '10 at 8:32
@Ressu - good point, how do we tell? Meta question posted:… – Jeremy Kerr Jul 29 '10 at 8:45
Depending on the outcome of that meta question, I'm likely to delete this. – Jeremy Kerr Jul 29 '10 at 9:24

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/
share|improve this answer
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 '13 at 17:53
up vote 14 down vote accepted

Looks like this will do it:

:set hidden

(in .vimrc)

share|improve this answer

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.

share|improve this answer
I'd rather not keep a permanently-visible buffer for each file; it's not unusual to have >20 files open at once. – Jeremy Kerr Jul 29 '10 at 8:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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