使用Vim的持久性撤消?

Vim 7.3中的新特性之一是“持久性撤消”,它允许在退出缓冲区时将无动词保存到文件中。

不幸的是,我还没有完全启用它,或者我必须错误地使用它。 以下是我迄今为止所尝试的:

我将以下内容添加到〜/ .vimrc中

set undofile " Save undos after file closes set undodir=$HOME/.vim/undo " where to save undo histories set undolevels=1000 " How many undos set undoreload=10000 " number of lines to save for undo 

之后,我应该能够打开任何文件,编辑它,然后保存 – closures它,当我再次打开它时,我应该能够撤销/重做,就像我永远不会离开。 不幸的是,这似乎并不是这样,因为从来没有任何不妥之处。

笔记:

  1. 我在Win 7上使用Vim 7.3而不是使用Vim项目。 持久性撤消是被烘烤的。

  2. $ HOME / .vim / undo存在于我的文件系统上

把它放在你的.vimrc ,如果它不存在,就创build一个undodir ,并启用持久性撤销。 在Windows和Linux上testing。

 " Put plugins and dictionaries in this dir (also on Windows) let vimDir = '$HOME/.vim' let &runtimepath.=','.vimDir " Keep undo history across sessions by storing it in a file if has('persistent_undo') let myUndoDir = expand(vimDir . '/undodir') " Create dirs call system('mkdir ' . vimDir) call system('mkdir ' . myUndoDir) let &undodir = myUndoDir set undofile endif 

我在我的_gvimrc中试过这个:

 " Persistent undo try set undodir=C:\vim\undodir set undofile catch endtry 

它开始工作时,我删除了try-catch支架,因此:

 " Persistent undo set undodir=C:\vim\undodir set undofile 

我不得不创build目录。

我猜想$ HOME不能像广告一样工作。

在我的系统上, :echo $HOME显示H:\,但是: e $HOME/表示: ~/无效的文件名。

你可以尝试一个绝对path,看看它是否治愈

现在可以按照预期工作:在Windows 7的Vim 7.4缓冲区中打开file.txt :setlocal undofile ,然后将更改保存到缓冲区,同时创buildundofile .file.txt.un~因为:set undodir? 报告“undodir =”。 默认情况下 – 即不需要手动指定。 您还可以:set undofile:set undofile