在spf13官方文档里,对undotree这个插件的描述:
Undotree
If you undo changes and then make a new change, in most editors the changes you undid are gone forever, as their undo-history is a simple list. Since version 7.0 vim uses an undo-tree instead. If you make a new change after undoing changes, a new branch is created in that tree. Combined with persistent undo, this is nearly as flexible and safe as git ;-)
Undotree makes that feature more accessible by creating a visual representation of said undo-tree.
QuickStart Launch using<Leader>u
.
个人渣翻译:
如果你反复修改与撤销,在大多数编辑器里,这种撤销带来的变化永远消失了。
因为它们的撤销历史记录是一个简单的线性表。至到vim7.0版本,使用undotree来取代以前的方式。
如果你做了任何改变,在记录树上会形成新的分支,它几乎像git一样灵活和安全。
undotree 带来了更容易创建一个可视化撤销树的表现特性。
spf13里快速启动该插件使用 <leader>u
我们来到undotree自己的官网,看看文档是怎么说的:
Description
Vim 7.0 added a new feature namedUndo branches. Basically it's a kind of ability to go back to the text after any change, even if they were undone. Vim stores undo history in a tree which you can browse and manipulate through a bunch of commands. But that was not enough straightforward and a bit hard to use. You may use:help new-undo-branches
or:help undo-tree
to get more detailed help. Now this plug-in will free you from those commands and bring back the power of undo tree.
个人渣翻译:
vim7.0添加了一个新特性,名为撤销分支。
基本上这是一种对任何更改后,还能回到文本的能力,即使它们被撤销了。
vim的撤销历史记录保存在树形结构上,你可以通过一系列的命令来浏览和操作,但是不够简单,有点难用。
你可以:help new-undo-branches或者:help undo-tree来获得更详细的帮助信息。
现在,这个插件会让你从那些命令中解放出来。
个人总结: 综合spf13和undotree的文档,可以这样理解,早期的vim撤销历史记录保存在线性表里,如果在撤销时出现分支操作,某些修改结果就永远消失了。
后来在vim7.0之后,官方(vim)添加了名为撤销分支的新特性,可以在任何撤销修改操作后,都能回到文本的某个记录点。
但是,这种特性不够简单,有点难用,需要记忆许多命令,于是有人在这个基础上,开发出了插件(undotree),帮助大家能简单使用新特性。
undotree插件本身的特性:
①可视化的历史记录
②活动更新不同面板
③添加和改变文本后高亮显示
④单一点击鼠标或按键,恢复到一个特定记录点
⑤可自定义快捷键和高亮
⑥在不同的面板显示变化
—————————分割线—————————————
Usage
-
Use
:UndotreeToggle
to toggle the undo-tree panel. You may want to map this command to whatever hotkey by adding the following line to your vimrc, take F5 for example.nnoremap <F5> :UndotreeToggle<cr>
-
Then you can try to do some modification, and the undo tree will automatically updated afterwards.
- There are some hotkeys provided by vim to switch between the changes in history, like
u
,<ctrl-r>
,g+
,g-
as well as the:earlier
and:later
commands. - You may also switch to undotree panel and use the hotkeys to switch between history versions. Press
?
in undotree window for quick help of hotkeys. - You can monitor the changed text in diff panel which is automatically updated when undo/redo happens.
- Persistent undo
- It is highly recommend to enable the persistent undo. If you don't like your working directory be messed up with the undo file everywhere, you may add the following line to yourvimrc in order to make them stored together.
// In your vimrc
if has("persistent_undo")
set undodir=~/.undodir/
set undofile
endif
用法
个人渣翻译:
① 使用:undotreeToggle 切换undo-tree面板,你可能想把该命令映射到某个快捷键上,以F5为例
nnoremap <F5> :UndotreeToggle<cr>
② 然后你可以试着做一些修改撤销,undotree会自动更新
③ 提供了一些由于vim历史版本变迁所带来的快捷键,比如 u,ctrl+r, g+,g-,以及:earlier
and:later 命令。
④你也可以选取undotree面板,使用热键来不同记录间切换,在undotree窗口里按下?获取热键帮助信息。
⑤当撤销/重做发生时,你可以监控到自动更新面板中文本的变化。
⑥坚持撤销:
高度推荐允许坚持撤销,如果你不喜欢在undo文件在工作目录里到处都是,可以在配置文件中添加如下代码:
// in your vimre
见上文
———————分割线————————————
个人总结:
官方(undotree)建议通过:UndotreeToggle 来切换开启面板,为什么spf13的快速启动是<leader>u?
这是因为我们整个插件包都由spf13完成,它已经修改了启动热键,<leader>u就相当于 :UndotreeToggle。
和官方例子中映射到F5一样,自己同样也可以再次修改映射,一种方式是保留<leader>u,重新 nmap,这样完成同一功能,最少会有两个快捷键。
另一种方式是先unmap掉<leader>u,再重新映射,显然第二种方式更清晰更好。
同时不要忘记,在安装spf13后,整个工作环境都与其息息相关,我们不能直接修改vimrc配置文件,而是在vimrc.local中添加修改。
个人实践:无论采用官方方式,还是<leader>u方式竟然无法启动undotree面板,为什么呢?
于是再次进入vim,使用:BundleInstall 安装,发现有几个插件没有安装成功,而undotree恰好是其中之一。
其后经过几天的思索与网上查找资料,包括spf13的官方文档,均没能解决该问题。
即在spf13安装后,其中自带的部分插件安装失败。
终于在今天2016/10/23日成功解决,原因在于我再次使用了:BundleInstall。
为什么同样的操作,带来了彻底不同的结果?
初步个人分析:网络延迟。
因为所有插件都需要从git上下载,考虑到国内的网络状况,再考虑到个人的网络状况。
可能在安装spf13时段,个人网络恰好不够稳定,引起了访问超时,也就造成了spf13集合包中部分插件安装失败。