- Mastering Vim
- Ruslan Osipov
- 178字
- 2021-06-10 18:51:26
Persistent undo and repeat
Like any editor, Vim keeps track of every operation. Press u to undo a last operation, and Ctrl + r to redo it.
To learn more about Vim's undo tree (Vim's undo history is not linear!) and how to navigate it, see chapter 4, Advanced Workflows .
Vim also allows you to persist undo history between sessions, which is great if you want to undo (or remember) something you've done a few days ago!
You can enable persistent undo by adding the following line to your .vimrc:
set undofile
However, this will litter your system with an undo file for each file you're editing. You can consolidate the undo files in a single directory, as seen in the following example:
" Set up persistent undo across all files.
set undofile
if !isdirectory("$HOME/.vim/undodir")
call mkdir("$HOME/.vim/undodir", "p")
endif
set undodir="$HOME/.vim/undodir"
If you're using Windows, replace the directories with %USERPROFILE%\_vim\undodir (and you'll be making changes to _vimrc instead of .vimrc).
Now, you'll be able to undo and redo your changes across sessions.
推薦閱讀
- 黑客攻防從入門到精通(實戰秘笈版)
- SoapUI Cookbook
- C# Programming Cookbook
- 零基礎學Scratch少兒編程:小學課本中的Scratch創意編程
- Java虛擬機字節碼:從入門到實戰
- Spring實戰(第5版)
- Python之光:Python編程入門與實戰
- Learning Laravel's Eloquent
- Scratch趣味編程:陪孩子像搭積木一樣學編程
- 計算機應用基礎教程(Windows 7+Office 2010)
- Oracle實用教程
- SQL Server 入門很輕松(微課超值版)
- 基于GPU加速的計算機視覺編程:使用OpenCV和CUDA實時處理復雜圖像數據
- Python程序設計:基礎與實踐
- Visual C++ 開發從入門到精通