How to undo all changes in a buffer made since it was open in Vim?

后端 未结 7 741
执念已碎
执念已碎 2021-01-30 08:38

How can I undo all changes since opening a buffer? I imagine there may be some form of :earlier that does this.

Update: Many are suggesting

相关标签:
7条回答
  • 2021-01-30 09:27

    To revert the current buffer to the state prior to the very first change recorded in the Vim undo list (see :help undo-tree), we can use two consecutive invocations of the :undo command:

    :u1|u
    

    The first command (:undo 1) reverts to the state of the buffer after the very first registered change, while the second command (:undo) reverts that first change itself.

    Starting with version 8.1 (see :helpg Patch 8.0.1441), Vim allows to pass the change number 0 as an argument to the :undo command to refer to the state before any registered changes, thus making it possible to achieve the same effect in a single-command invocation:

    :u0
    
    0 讨论(0)
提交回复
热议问题