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.
How did you format the column? It happened so fast that I was unable to catch that.
Okay I found out this was done using Tabular.vim. Keep up the great work, Vim FTW!
Yep, that’s right! I’m going to have to write up that tip soon!
Thanks for the tip, very useful.
Is this a plugin to auto-align the table?
Yep, tabular.vim I’m going to write this up for next week!
That’s a great tip!
I used to use ctrl+w to undo word by word typed in insert mode.
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
Good point, thanks! I will edit the post to make it clear it’s only all your changes of those changes are on one line.