Undo from Insert Mode

4.6
(183)

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.

How useful was this tip?

Average rating 4.6 / 5. Vote count: 183

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

81 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

8 thoughts on “Undo from Insert Mode”

  1. Nice tip, but CTRL-u in insert mode deletes all characters before the cursor in the current line. See :help i_CTRL-u

    :help i_CTRL-u

Leave a reply

Your email address will not be published. Required fields are marked *