DEV Community

Do you know Vim can execute normal mode command while in insert mode?

Igor Irianto on August 12, 2019

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. Recentl...
Collapse
 
bootcode profile image
Robin Palotai • Edited

Nice! Let me add my favorite here:

Shift-j to merge next line
gqip to reformat paragraph
gqj to reformat over next line

These together are mostly enough to avoid manual reflow to honor line length limit.

Collapse
 
iggredible profile image
Igor Irianto

Good use cases! I never really knew about the last two - thanks! Always learning something new about vim.

Collapse
 
skydevht profile image
Holy-Elie Scaïde

I've known about insert-normal, but I never used it really. I've remapped to and my brain is already wired to leave insert more whenever I pause. But thanks for the insight, it's always helpful to know more about vim!

Collapse
 
drhyde profile image
David Cantrell

I've been vimming for ... I don't know how many years. probably since 1994 because I see that it was in Slackware 2. I didn't know about this. Thanks!

Mind you, now that I know about it I'm not sure whether I'll use it. <ESC> command i is soooo deeply ingrained in my muscle-memory that I'm not sure I'll ever be able to stop doing it :-)

Collapse
 
iggredible profile image
Igor Irianto

I agree. It is ingrained in my muscle memory too - and I haven't used vim for more than 2 years!
Learning to be more thoughtful when I'm typing and breaking from the <Esc> normal-command habit slowly... :) This is going to take a while!

Collapse
 
kr1ssxd profile image
Kriss

Thx for sharing !

What I find helpful is mapping some combinations to shortcuts in insert mode to ease cursor movement and/or scrolling :

" Movement in insert mode
inoremap <C-h> <C-o>h
inoremap <C-j> <C-o>j
inoremap <C-k> <C-o>k
inoremap <C-l> <C-o>l
" Also allow line-wise scrolling
inoremap <C-e> <C-o><C-e>
inoremap <C-y> <C-o><C-y>
Collapse
 
iggredible profile image
Igor Irianto

Woah. This is mind-blowing. I'll have to try this!

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

Despite having used Vim for almost a decade (possibly more, I don't quite remember exactly when I started using it), this is actually completely new to me.

OTOH, I'm not too surprised when I find something I didn't know about Vim (or just vi in general), I still average about one new thing I learn about it every week or so these days, but then, I never really went out of my way to learn anything but the absolute basics originally (and it was Nethack, not Vim, that got me in the habit of using hjkl for movement).

Collapse
 
robertomaurizzi profile image
Roberto Maurizzi

Nice, now I can stop invoking Anubis every time I want to switch to another tab while staying in insert mode ;-)

Collapse
 
iggredible profile image
Igor Irianto

Haha, good use case! Stay away from the underworld >:)

Collapse
 
madox2 profile image
Martin Bielik

My favourite is C-o o or C-o O, starting on next/previous line.

Collapse
 
iggredible profile image
Igor Irianto

I used o/ O all the time and didn't think of that. Good rec!

Collapse
 
mikaoelitiana profile image
Mika Andrianarijaona

😲😲😲😲😲😲 thanks for sharing!!!!! it's a real discovery for me, I really love it.

Collapse
 
iggredible profile image
Igor Irianto

Haha, glad you found it helpful! It totally changed my workflow when I discovered this too!

Collapse
 
bakadesu profile image
バカです

There's mine:

inoremap <up> <C-o>:resize +5<cr>
inoremap <left> <C-o>:vertical resize -5<cr>
inoremap <right> <C-o>:vertical resize +5<cr>
inoremap <down> <C-o>:resize -5<cr>
Collapse
 
iggredible profile image
Igor Irianto

Haha nice!! I thought of mapping my arrow keys as well, good call!