Vim undo:文件写入后撤消更改

bro*_*oot 24 vim undo

在我的vim代码中,我做了很多更改,然后做了一个ZZ(保存并退出).但后来我意识到我不需要那些改变.有没有一种方法可以在使用某些缓冲区进行更改之前返回状态,在缓冲区中仍可能存储该数据.保存和退出后我没有做任何更改.

bro*_*oot 43

在vim中有持久的撤销选项,:h persistent-undo
注意:它是在VIM 7.3版本中引入的,因此对于早期版本,它将无法工作.

它可以通过在您的下列文字中放置以下内容来打开.vimrc:

if has('persistent_undo')      "check if your vim version supports it
  set undofile                 "turn on the feature  
  set undodir=$HOME/.vim/undo  "directory where the undo files will be stored
  endif     
Run Code Online (Sandbox Code Playgroud)

  • 请注意,您必须确保该目录存在才能使其正常工作. (6认同)