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: 213

Filed under:
|

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

Related posts about vim

Related posts about remapping

  • Remapping the Windows key in Parallels

    as seen on Super User - Search for 'Super User'
    I'm running XP on Parallels 4 for Mac, and it's working well enough, however one thing that's bothering me more and more as I go along is the way it constantly assumes every press of the command key means I want the start menu to come up. I've tried to remap it in the Parallels preferences, but all… >>> More

  • Dvorak hotkey remapping in vim, worth it?

    as seen on Super User - Search for 'Super User'
    I've been trying to learn the dvorak keyboard layout of late and I have been making some good progress this time around. The trouble I am finding now is that all of my hotkeys are all in the wrong places. As a vim user this is particularly troubling. I have found good resources to switch the bindings… >>> More

  • Apple keyboard key remapping under Ubuntu

    as seen on Super User - Search for 'Super User'
    I have an Apple keyboard that I simply love. I now hate my regular keyboard at work. I just have a small problem with the Apple keyboard. There is no "insert" key. The one that is usually Insert on regualr keyboard is replaced by the "fn" key. I would like to keep the fn functionality, as it is useful… >>> More

  • Selective Pointer device remapping in linux

    as seen on Super User - Search for 'Super User'
    I just got an HP 2710p (hp tablet, with digitizer), and I've played around with linux for a while now, and thought I would go ahead and install it. Everything works fine, excepting normal tablet functions, which is to be expected. I'm working on the screen rotation, and there are on-screen keyboards… >>> More

  • WPF Keyboard Remapping

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hello, I am trying to remap the input of a textbox. For example. If a user enters a N then I would like to change it to a 9. I thought it might be best to try and catch it in the PreviewKeyDown event although I will also need to process paste attempts (I can solve that bit I think). Is PreviewKeyDown… >>> More