使用 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
之后,我应该能够打开任何文件,编辑它,然后保存关闭它,当我再次打开它时,我应该能够撤消/重做,就好像我从未离开过一样。不幸的是,情况似乎并非如此,因为没有写入任何撤消文件。
注意:
我在 Win 7 上使用来自 Vim without Cream 项目的 Vim 7.3。持久撤消已内置。
$HOME/.vim/undo 存在于我的文件系统上
One of the new features in Vim 7.3 is 'persistent undo', which allows for the undotree to be saved to a file when exiting a buffer.
Unfortunately, I haven't quite been able to get it properly enabled, or I must be using it wrong. Here's what I've tried so far:
I added the following to ~/.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
After this, I supposedly should be able to open any file, edit it, then save-close it, and when I open it again I should be able to undo/redo as if I'd never left. Unfortunately, this doesn't seem to be the case, as no undofile is ever written.
Notes:
I'm on Win 7 using Vim 7.3 from the Vim without cream project. Persistent undo is baked-in.
$HOME/.vim/undo exists on my file system
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将其放入
.vimrc
中以创建一个undodir
(如果它不存在)并启用持久撤消。在 Windows 和 Linux 上进行了测试。Put this in your
.vimrc
to create anundodir
if it doesn't exist and enable persistent undo. Tested on both Windows and Linux.我在我的 _gvimrc 中尝试了这个:
当我删除 try-catch 括号时,它开始按照广告工作,因此:
我必须创建该目录。
I tried this in my _gvimrc:
It started working as advertised when I deleted the try-catch bracket, thus:
I had to create the directory.
我想 $HOME 并不像宣传的那样工作。
在我的系统上,
:echo $HOME
显示 H:\,但: e $HOME/
表示:~/
文件名无效。你可以尝试用绝对路径看看是否能解决这个问题
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
现在可以按预期工作:
file.txt
在 Windows 7 上的 Vim 7.4 缓冲区中打开,:setlocal undofile
,然后保存对缓冲区的更改,以及撤消文件.file.txt.un~
会同时创建,因为:set undodir?
报告“undodir=”。默认情况下 - 即无需手动指定。您还可以在模型行中:set undofile
。This now works as expected:
file.txt
open in a Vim 7.4 buffer on Windows 7,:setlocal undofile
, then save a change to the buffer, and the undofile.file.txt.un~
is created alongside because:set undodir?
reports that "undodir=." by default - ie no need to specify this manually. You can also:set undofile
in a modeline.现在,如果有人使用 nvim 并想在 undotree 中使用持久撤销。
opt.undodir = "~/.undodir"
opt.undofile = true
Now if someone using nvim and want to use Persistent undo in undotree.
opt.undodir = "~/.undodir"
opt.undofile = true