官术网_书友最值得收藏!

  • 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 4Advanced 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.

主站蜘蛛池模板: 依安县| 毕节市| 敦煌市| 祥云县| 梧州市| 若羌县| 长葛市| 普洱| 朝阳县| 临江市| 韶山市| 叙永县| 中山市| 达日县| 施秉县| 嘉峪关市| 鄢陵县| 山东省| 湖南省| 山东省| 尼木县| 东丰县| 平安县| 安吉县| 鹤峰县| 甘谷县| 延安市| 二手房| 平泉县| 公安县| 西宁市| 闸北区| 北川| 柘城县| 呼玛县| 乌兰县| 九寨沟县| 峡江县| 馆陶县| 齐河县| 修水县|