Vim comes with a very powerful built-in undo engine. While most editors support a linear undo/redo, where all changes are tracked sequentially, Vim maintains a tree of changes. For now, we will describe basic undo and redo operations, which make up the majority of undo operations, and save the more complicated operations for a future section.
Let's demonstrate the basics with the following buffer:
First, make some edits. For example, lets delete 4 lines:
Now, that we have made a change, we can undo the most recent change by typing u. The u command also takes a count, so if you want to undo the last 3 changes you can type 3u.
If you prefer to use command-line mode, you can achieve the same result with the :undo command:
:undo [count]
Now, let's redo the change, using C-R
C-R also accepts an optional count, and the command-line option is:
:redo [count]
Check back soon to learn more about more advanced undo and redo operations in Vim.