105

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

在此之后,我应该能够打开任何文件,编辑它,然后保存关闭它,当我再次打开它时,我应该能够撤消/重做,就好像我从未离开过一样。不幸的是,情况似乎并非如此,因为没有写入任何撤消文件。

笔记:

  1. 我在 Win 7 上使用来自 Vim without cream 项目的 Vim 7.3。持久撤消是内置的。

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

4

5 回答 5

56

如果它不存在并启用持久撤消,请将其放入您.vimrc的创建。undodir在 Windows 和 Linux 上都经过测试。

" Put plugins and dictionaries in this dir (also on Windows)
let vimDir = '$HOME/.vim'

if stridx(&runtimepath, expand(vimDir)) == -1
  " vimDir is not on runtimepath, add it
  let &runtimepath.=','.vimDir
endif

" 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
于 2014-03-27T00:53:11.370 回答
8

我在我的 _gvimrc 中试过这个:

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

当我删除 try-catch 括号时,它开始像宣传的那样工作,因此:

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

我必须创建目录。

于 2012-03-17T17:51:46.390 回答
3

I suppose $HOME doesn't work as advertised.

On my system, :echo $HOME shows H:\, but : e $HOME/ says: ~/ invalid filename.

You could try with an absolute path to see whether it cures it

于 2011-04-18T10:22:46.913 回答
1

这现在按预期工作:file.txt在 Windows 7 上的 Vim 7.4 缓冲区中打开:setlocal undofile,然后将更改保存到缓冲区,并同时.file.txt.un~创建撤消文件,因为:set undodir?报告“undodir=。” 默认情况下 - 即无需手动指定。您也可以:set undofile在模式行中。

于 2014-12-12T09:29:26.427 回答
0

如果你正在寻找 %TEMP%.(filename).un~ 你不会找到它

文件名将是 C%%Users%%(username)%_vimrc 行

我不知道为什么

于 2020-10-18T02:44:53.117 回答