使用 Vim 的持久撤销? [英] Using Vim's persistent undo?
问题描述
Vim 7.3 中的一项新功能是持久撤消",它允许在退出缓冲区时将撤消树保存到文件中.
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:
我将以下内容添加到 ~/.vimrc
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.
注意事项:
我正在使用来自 Vim without cream 项目的 Vim 7.3 的 Win 7.持久性撤消已内置.
I'm on Win 7 using Vim 7.3 from the Vim without cream project. Persistent undo is baked-in.
$HOME/.vim/undo 存在于我的文件系统中
$HOME/.vim/undo exists on my file system
推荐答案
把它放在你的 .vimrc
中以创建一个 undodir
如果它不存在并启用持久化撤消.在 Windows 和 Linux 上均已测试.
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
这篇关于使用 Vim 的持久撤销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!