如何让 vim 保留其撤消历史?

Jer*_*err 3 vim

如果我正在使用 vim 编辑两个文件,更改为另一个文件 ( :bnext, :bprev ) 似乎会从打开的文件中删除撤消历史记录 - 点击 'u' 键报告“已经是最旧的更改”。

例如:

  1. vim testfile1 testfile2
  2. 添加一些东西到 testfile1
  3. :w
  4. :bn
  5. :bp
  6. u
  7. 哎呀!无法撤消!

有没有办法为不可见缓冲区保留此历史记录?

Dan*_*son 6

对于 Vim 7.3+,我认为还有另一种方法适用于这种情况。在$VIMRC

set undodir=~/.vim/undodir
set undofile
Run Code Online (Sandbox Code Playgroud)

undodir存在的需要。

来自 Vim 的帮助:

                        *'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!
Run Code Online (Sandbox Code Playgroud)


Jan*_*nen 5

尝试将其放入~/.vimrc文件中:

set hid
Run Code Online (Sandbox Code Playgroud)