使用 Vim 的持久撤消功能?

发布于 2024-11-02 04:22:03 字数 619 浏览 3 评论 0原文

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 存在于我的文件系统上

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:

  1. I'm on Win 7 using Vim 7.3 from the Vim without cream project. Persistent undo is baked-in.

  2. $HOME/.vim/undo exists on my file system

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

傾城如夢未必闌珊 2024-11-09 04:22:03

将其放入 .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

Put this in your .vimrc to create an undodir if it doesn't exist and enable persistent undo. Tested on both Windows and 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
魔法少女 2024-11-09 04:22:03

我在我的 _gvimrc 中尝试了这个:

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

当我删除 try-catch 括号时,它开始按照广告工作,因此:

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

我必须创建该目录。

I tried this in my _gvimrc:

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

It started working as advertised when I deleted the try-catch bracket, thus:

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

I had to create the directory.

待"谢繁草 2024-11-09 04:22:03

我想 $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

伪装你 2024-11-09 04:22:03

现在可以按预期工作: 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.

峩卟喜欢 2024-11-09 04:22:03

现在,如果有人使用 nvim 并想在 undotree 中使用持久撤销。

  • 在 options.lua 或 init.lua 文件中添加底部 2 行
    opt.undodir = "~/.undodir"
    opt.undofile = true

Now if someone using nvim and want to use Persistent undo in undotree.

  • add bottom 2 lines in options.lua or init.lua file
    opt.undodir = "~/.undodir"
    opt.undofile = true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文