While editing text files with vim we can make some little mistakes or want to revert to the previous states. In Microsoft Word there is features rich undo and revert functions. The similar undo and revert functionalities provided by vim too.
在用vim编辑文本文件时,我们可能会犯一些小错误,或者想恢复到以前的状态。 在Microsoft Word中,具有丰富的撤消和还原功能。 vim也提供了类似的撤消和还原功能。
清单变更 (List Changes)
In order to revert back we can list changes and related information. With the :undolist
command we will list number of changes and time information. We will get following information.
为了恢复原状,我们可以列出更改和相关信息。 使用:undolist
命令,我们将列出更改数量和时间信息。 我们将获得以下信息。
- Change number 变更号码
- Change Time变更时间
- Is saved已保存
:undolist

仅撤消上一次更改(Undo Only Last Change)
While writing text or developing applications we generally made a lot of change in the file. At some point we can see that there is mistakes or we should return to the previous versions of file. We can use u
shortcut to revert or undo last change. We can use u
multiple times which will go previous versions step by step.
在编写文本或开发应用程序时,我们通常会对文件进行很多更改。 在某些时候,我们可以看到有错误,或者我们应该返回到以前的文件版本。 我们可以使用u
快捷方式还原或撤消上一次更改。 我们可以多次使用u
,它将逐步使用以前的版本。
u
重做撤消更改 (Redo Changes which Undo)
So while going back to the previous versions we noticed that we have to to forward . As vim stores changes in a structural way we can return new versions or redo with the following command.
因此,在回到以前的版本时,我们注意到我们必须前进。 随着vim以结构化方式存储更改,我们可以使用以下命令返回新版本或重做。
Ctrl+R
返回原始版本 (Return To The Original Versions)
If we are sure and want to go first versions we can use following command.
如果我们确定要发布第一个版本,可以使用以下命令。
U
尽早还原指定的更改数量 (Revert Specified Number Of Change Earlier)
Reverting back one by one is a trivial task. As we see in previous examples we can list undo list. We can use one of the intermediate steps to revert back. In this example we will revert 5 steps back.
一步一步地还原是一项微不足道的任务。 正如我们在前面的示例中看到的,我们可以列出撤消列表。 我们可以使用中间步骤之一来还原。 在此示例中,我们将向后退5步。
:earlier 5
稍后还原指定的更改数量 (Revert Specified Number Of Change Later)
We can also revert to the forward which means we will go to the latest changes. In this example we will revert to later 10 steps with the following command.
我们还可以恢复到前进状态,这意味着我们将进行最新更改。 在此示例中,我们将使用以下命令还原到后面的10个步骤。
:later 10
翻译自: https://www.poftut.com/vim-undo-redo-operations/