[vim]撤销树插件——Gundo
Undo tree
在 vim 中,可以 :undolist 查看操作歷史,正如 gundo doc 所言:
You know that Vim lets you undo changes like any text editor. What you might not know is that it doesn't just keep a list of your changes — it keeps a tree of them.
儘管如此,直接 :undolist 仍舊痛苦,只需一瞥簡陋而絕望的列表就會將它束之高閣。
爲此,gundo 產生:
Gundo is a plugin to make browsing this ridiculously powerful undo tree less painful.
安裝和配置
若使用 vim-plug 插件管理器,只需添加:
Plug 'sjl/gundo.vim'
gundo 目前默認使用 python2,可以在 .vimrc 或 init.vim(neovim) 中設置爲 python3:
let g:gundo_prefer_python3=1
使用
:GundoToggle
左邊會新增一欄,頂部有提示信息,使用 j/k 可以在歷史中跳躍。下面會顯示文件的狀態,有點像 git 的版本更新記錄。

方便起見,設置一個快捷鍵:
nnoremap <leader>g :GundoToggle<cr>
在普通模式下,可以按 ",g" 切換 Gundo Tree。
自定義 leader 鍵:
let mapleader = ","
浙公网安备 33010602011771号