Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 3 down vote accepted

Try to put this in your ~/.vimrc file:

set hid
share|improve this answer
    
Perfect. Thanks! –  Jeremy Kerr Jul 29 '10 at 9:18
add comment

For Vim 7.3+, there is another way that I believe applies in this case. In $VIMRC:

set undodir=~/.vim/undodir
set undofile

The undodir needs to exist.

From Vim's help:

                        *'undodir'* *'udir'*
'undodir' 'udir'    string  (default ".")
            global
            {not in Vi}
            {only when compiled with the |+persistent_undo| feature}
    List of directory names for undo files, separated with commas.
    See |'backupdir'| for details of the format.
    "." means using the directory of the file.  The undo file name for
    "file.txt" is ".file.txt.un~".
    For other directories the file name is the full path of the edited
    file, with path separators replaced with "%".
    When writing: The first directory that exists is used. "." always
    works, no directories after "." will be used for writing.
    When reading all entries are tried to find an undo file.  The first
    undo file that exists is used.  When it cannot be read an error is
    given, no further entry is used.
    See |undo-persistence|.

                        *'undofile'* *'udf'*
'undofile' 'udf'    boolean (default off)
            local to buffer
            {not in Vi}
            {only when compiled with the |+persistent_undo| feature}
    When on, Vim automatically saves undo history to an undo file when
    writing a buffer to a file, and restores undo history from the same
    file on buffer read.
    The directory where the undo file is stored is specified by 'undodir'.
    For more information about this feature see |undo-persistence|.
    The undo file is not read when 'undoreload' causes the buffer from
    before a reload to be saved for undo.
    WARNING: this is a very new feature.  Use at your own risk!
share|improve this answer
add comment

Your Answer

 
discard

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.