How to map command in vim that maintains mode when invoked?
Posted
by
Phoenix
on Super User
See other posts from Super User
or by Phoenix
Published on 2011-06-20T20:10:21Z
Indexed on
2011/06/22
8:25 UTC
Read the original article
Hit count: 210
I'm configuring vim in Mac OS X's Terminal app to do useful things with my arrow keys (among others).
For example, I want option-left to move the cursor back one word, similarly to how it works in other Mac applications.
In normal mode, this is easy enough; I can simply map the sequence to b
. But when I'm in insert mode, I want to stay in insert mode (i.e., map the sequence to <c-o>b
.
In my .vimrc` file, I have these lines:
nmap ^[[xol~ b
imap ^[[xol~ <c-o>b
Where ^[[xol~
is the character sequence that I've configured Terminal to send when I press option-left.
This works, but it gets pretty tedious, especially when I've got nearly two dozen commands that I want to map.
Is there a better way to do this?
© Super User or respective owner