Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running vim on a Linux VM that I'm ssh'd into via Mac OS X's Terminal app, and I want to configure it 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?

share|improve this question

2 Answers 2

Yes, there is a better way. Download and install MacVim, it comes with a lot of Mac OS X keybindings by default and some more if you add a simple option (which I don't have at hand) to your .vimrc. Plus it supports more colors than Terminal.app and is better integrated in the OS than CLI Vim.

IMO your fixation on having Mac OS X keybindings in vim in the terminal (of all places) and to stay in INSERT mode are quite big obstacles on an already steep learning curve. You should leave INSERT mode as soon as you are done with actual text insertion and just use Vim's amazing power in a more productive way.

If you want a modeless CLI editor you may try emacs, joe or nano ranked from über powerful to really simple. If you want a modeless GUI editor you may try TextMate or Sublime Editor but none will be remotely as powerful as Vim.

share|improve this answer
    
Thanks for the suggestion, but I'm actually running vim on a Linux VM, so Mac applications aren't an option for me in this case (I've updated the question updated to reflect this). –  todofixthis Jun 22 '11 at 12:00
    
@Phoenix — It doesn't change anything to the fact that you want to use Vim in a very unproductive/unnatural way. That said, I don't see a better way to achieve your goal. You'll need to remap all of Vim's basic commands to escape sequences just like you did for b, that's a lot of commands and you are going to come out of keys and Mac OS X keybindings quickly. Seriously, learn the proper way it will pay very quickly. –  romainl Jun 22 '11 at 12:36
    
Your opinion has been noted, thanks. –  todofixthis Jun 22 '11 at 13:31
up vote 0 down vote accepted

Creating the separate mappings for each mode seems to do the trick. Perhaps that is the best way to do it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.