DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

为vim增加undo功能


vim 7.3+后对undo功能有了很大改进,配合undotree 可以实现完全记录本地改动。

安装和配置

手工创建vim的undo持久化目录:mkdir -p $HOME/.vim/undo.

在.vimrc中增加:

" undo & undotree configs
set undodir=$HOME/.vim/undo/ "make sure this folder exists
set undofile
cabbrev ut UndotreeToggle<CR>

Plugin 'mbbill/undotree'

并安装:vim +PluginClean +PluginInstall.

使用

使用:ut打开/关闭undotree窗体; 在undotree窗体中,用?打开/关闭帮助信息。 查看完整的使用说明::h undotree.txt

Note

由于使用纯vimscript而不是Python,undotree比Gundo更轻便。

在.vimrc中可以通过undolevels和undoreload设置,默认值似乎是100.

参考:

  • http://vimdoc.sourceforge.net/htmldoc/options.html#'undolevels'

  • http://stackoverflow.com/questions/5700389/using-vims-persistent-undo

gVim on Windows

Windows上的gVim默认将持久化的undo文件放在当前文件夹里, myfile.txt的undo文件名为.myfile.txt.un~,会把文件夹搞得很乱, 增加版本管理系统的负担。 一种解决方法是不让gVim生成undo文件,这样不太好, 另一种是学习Linux把undo文件放在专门的文件夹下,具体过程如下。

在Windows用户根目录(C:\Users\)下创建.vim\undo目录, Windows用户根目录下的.vimrc文件中添加:

set undodir=$HOME/.vim/undo/
set undofile
set undolevels=1000
set undoreload=10000


Published

Oct 20, 2016

Last Updated

Oct 20, 2016

Category

Tech

Tags

  • undotree 1
  • vim 92

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor