How to go back (ctrl+z) in vi/vim
205,962
Solution 1
You can use the u
button to undo the last modification. (And Ctrl+R to redo it).
Read more about it at: http://vim.wikia.com/wiki/Undo_and_Redo
Solution 2
The answer, u
, (and many others) is in $ vimtutor
.
Solution 3
Here is a trick though. You can map the Ctrl+Z keys.
This can be achieved by editing the .vimrc
file. Add the following lines in the '.vimrc` file.
nnoremap <c-z> :u<CR> " Avoid using this**
inoremap <c-z> <c-o>:u<CR>
This may not the a preferred way, but can be used.
** Ctrl+Z is used in Linux to suspend the ongoing program/process.
Solution 4
Just in normal mode press:
- u - undo,
- Ctrl + r - redo changes which were undone (undo the undos).
Author by
Slazer
Updated on June 26, 2021Comments
-
Slazer almost 3 years
In normal text editors [with all due respect to Vim] there is a shortcut Ctrl+Z when you have done something nasty and want to return to the previous version of the text. Like BACK button in Word. I wonder how can you achieve this behaviour in Vim.
-
Cyclonecode over 11 years
-
Chris Morgan over 11 yearsThe Vim documentation is also very good -
:help undo
will find you your answer on this, for example. -
karth over 11 yearsbefore diving into vim completely, I suggest you go through the (interactive) tutorial
-
Slazer over 11 yearsThank you all and sorry for this q. Must read more next time.
-
mancocapac over 4 yearson linux, CTRL-Z in vi/vim/gvim mean escape to the console, or put this in the background. you then do whatever you want on the console and type fg (foreground) to bring you back into vim edit session.
-
-
simhumileco about 5 yearsI know that most of my answer is duplicated with those already present, but the value added of my answer is redo as
Ctrl + r
(lower caser
) based on the documentation. Nobody before put it here. In addition, I tried to make the answer as clearly as possible. -
NeilG almost 5 yearsI map U to redo so I can undo / redo quickly, the entire edit history if necessary, in vimrc: nnoremap U <C-R>
-
Paiusco almost 4 yearsup vote only because I've never heard of
vimtutor
before