How to map command in vim that maintains mode when invoked?
- by Phoenix
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?