Undo from Insert Mode
Do you ever make mistakes? Me neither. But let’s just say I have a friend who uses this tip all the time since he learned it.
Imagine you enter insert mode, you type some text, but it’s not quite right so you want to undo it. The logical way to do this is press
<Esc> to exit insert mode and go back to normal mode. Then you press
u to undo, then press
i to re-enter insert mode and try again.
But there is a better way: Pressing
<ctrl-u> while in insert mode will undo everything you have entered on the current line leave you in insert mode. You just saved replace 3 key presses with a single key-combo. From the help docs:
:help i_CTRL-U Delete all entered characters before the cursor in the current line. If there are no newly entered characters and 'backspace' is not empty, delete all characters before the cursor in the current line.
Here’s a video of the tip in action. After making some edits to the list, I use
O to insert a line above with a description. Halfway through, I decide I don’t like it but instead of undoing my entire insert, I use
<ctrl-u> to stay in insert mode but undo all my changes and take me back to where I started insert mode.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?