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

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

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

例如:

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

有什么方法可以保留不可见缓冲区的历史记录吗?

答案1

尝试将其放入你的的〜/ .vimrc文件:

set hid

答案2

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

set undodir=~/.vim/undodir
set undofile

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!

答案3

相关内容