DEV Community

The Only Vim Insert-Mode Cheatsheet You Ever Needed

Igor Irianto on May 14, 2020

Follow @learnvim for more Vim tips and tricks! Insert mode is an important mode in vim. I've put together a cheatsheet with 8 tips and tricks to u...
Collapse
 
v6 profile image
🦄N B🛡 • Edited

Ctrl-[ " exits insert mode and go to normal mode

I wonder if this is the reason the Kinesis-2 puts the [key in the upper right.

I'll just tell myself that's why to help me cope.

Ctrl-o 100ihello
Ctrl-o 10Ahello

These didn't work.

Also, the commands you posted were not able to pull content directly from theregister please help.

Collapse
 
iggredible profile image
Igor Irianto

Ctrl-o 100ihello
Ctrl-o 10Ahello
These didn't work.

Make sure you are running it from insert mode and make have no other plugin / settingblocking it. I tested it by running my vim without plugin, and it works (v8.2).
repeat

Ctrl-r also works fine on my machine when I run vim without plugin. My suspicion is that you may have a plugin/ setting that overwrites Ctrl-r commands.

register

Collapse
 
rj722 profile image
Rahul Jha

Amazing article there @iggredible !

BDW, how did you get these key events in the GIF?

Thread Thread
 
iggredible profile image
Igor Irianto • Edited

Thanks Rahul! Appreciate it :)

I used gifox (gifox.io/). It's a paid app, but it is worth it. Very convenient. I use it almost every day!

Collapse
 
snawaz profile image
Sarfaraz Nawaz • Edited

Awesome article. I wish I knew o and O commands before. Is there any similar commands that inserts an empty line before (and after) and stays in the normal mode. Sometimes while formatting, I just want to insert empty lines while staying in the normal mode.

Collapse
 
snawaz profile image
Sarfaraz Nawaz

ah, I can do this instead:

" insert an empty line without leaving normal mode
nnoremap <leader>o o<Esc>     
nnoremap <leader>O O<Esc>
Collapse
 
iggredible profile image
Igor Irianto • Edited

I don't think it exists. But luckily, we can always map it if it doesn't exist. Something like:

:nnoremap <leader>o o<esc>

You can change <leader>o to whatever mapping you want :)

EDIT: apparently we posted (partially) exact same mapping within 5 minutes haha!!

Collapse
 
snawaz profile image
Sarfaraz Nawaz

Eventually, I used this instead:

nnoremap <silent> oo :<C-u>call append(line("."),   repeat([""], v:count1))<CR>
nnoremap <silent> OO :<C-u>call append(line(".")-1, repeat([""], v:count1))<CR>  
Enter fullscreen mode Exit fullscreen mode

It has 3 advantages:

  • first) I dont have to hit two different keys, instead press the same key twice (quickly though),
  • second) the cursor stays on the same line as it was before.
  • third) I can insert more than one lines like this: 10oo which inserts 10 lines after the current one!

Not my solution. I just copied it from here: vi.stackexchange.com/a/3881/21711 .. That's a great answer!

Collapse
 
voyeg3r profile image
Sérgio Araújo

I think the only thing missing here is how to insert registers literally, for this a suggest these two great posts:

1 - vimcasts.org/episodes/pasting-from...
2 - thoughtbot.com/blog/how-to-edit-an...

Collapse
 
midenok profile image
Aleksey Midenkov

Strange there is no exit insert mode and abort all changes done in insert mode (or did I miss something). I'd expect such function from multi-modal design.

Collapse
 
mattalxndr profile image
Matthew Alexander

I can't believe I never knew about Ctrl+O while in Insert mode. That's something I'll end up using a lot. Registered an account to let you know Thanks!