Vim: temporary normal mode while holding Alt in insert mode
Asked Answered
J

0

6

I wonder if there's a way to make the Alt (or another key) work like Ctrl-o, but for as long as the key is pressed. For example, if you're in insert mode and want to move 10 lines down and 2 words forward, you could hold Alt, press 10jww and then release the Alt key. It is much faster than pressing Ctrl-o before each movement or leaving insert mode and having to enter it back again.

I did some remappings to use the main movement keys from insert mode while holding Alt:

inoremap <A-h> <C-o>h
inoremap <A-j> <C-o>j
inoremap <A-k> <C-o>k
inoremap <A-l> <C-o>l
inoremap <A-w> <C-o>w
inoremap <A-e> <C-o>e
inoremap <A-b> <C-o>b

But that is limited, if I wanted to use numbers to move multiple steps for example, I would need to map a new key binding for each movement and for each number.

If it was possible to do something like enter normal mode on Alt (keydown) and go back to insert on Alt (keyup), then all normal mode key bindings should be available only by holding one key.

Jegar answered 19/1, 2021 at 20:35 Comment(4)
I wander how this could make you faster if you have one hand anchored on a key...Adelaidaadelaide
Well, actually I use my left thumb to hold Alt while w, e, 1, 2, 3, 4 and 5 are easily reachable by my other fingers on the left hand and my right hand is free to press h, j, k, l , b, and the other numbers. Those would be the only important keys and I know that this mode wouldn't be worth to use with much longer key bindings.Psychopathy
You can make mappings that use a count?Esta
Not those using Alt, that's the main feature I'm looking for in them. I've just discovered how to make mappings that use count on this article, but looks like Alt adds an extra 3 to the count, so if try to make it count 2 or 7 times, it ends up counting 23 or 73 times.Psychopathy

© 2022 - 2024 — McMap. All rights reserved.