Follow @learnvim for more Vim tips and tricks!
Vim has been my go-to editor for the last 1.5 years, yet I am still learning something new. Recently I learned about "Insert Normal" mode and I'd like to share how you can use this mode to code faster in vim!
Feedbacks are highly appreciated. If you think of more ways to save keystrokes using this mode, feel free to share in the comments!
Glad you asked!
It is a mode in insert mode where you can execute normal mode commands. Instead of switching modes from
normal -> (do normal mode stuff) ->
insert, you can execute normal code commands while remaining in insert mode.
All you need to do is to press
C-o while in insert mode.
How can you tell that you're in insert-normal mode? In insert mode, you can see
-- INSERT -- indicator on bottom left. If we press
C-o, it will change into
-- (insert) --.
Important: you can only execute one command in this mode. After executing a normal mode command, you're back to insert mode.
Even with this limitation, this is still a powerful feature. Let's give some examples what we can do with insert-normal mode.
Let's say while typing, you wanted to add a word in the beginning of current line. Do
C-o 0 to jump to the beginning of the line, add the word, then jump back with to the end with
Maybe you are adding something after comma in the same line, just do
C-o T , and you'll jump right after the comma.
C-o $ to jump back to the end.
You can always mix it with other vim motions. I find
H, M, L, , () useful for quick navigation.
I am typing this article in vim. As I am typing this, I am at the bottom of the screen. I can center my current position by doing
Say I want to type
* 100 times. I can just type
C-o 100 i * <esc> (the downside is, this will force you to leave insert mode).
If I wanted to delete a block of text from my current position to an anchor, say a comma, I can just do
C-o d T ,
These are some ways we can take advantage of insert-normal mode.
I am interested to learn how other devs can take advantage of insert-normal mode. What other ways do you guys think insert-normal mode can be used?