Vim: temporary normal mode while holding Alt in insert mode

Viewed 274

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.

0 Answers
Related