Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to switch buffers (:bn! / :bp!) in MacVim, using shortcuts like

Alt (Option) - Left Arrow Key/Right Arrow Key

So far I wasn't able to do that.

Here's my mapping for the keys, which works perfectly fine in Linux, but not on MacOS:

map <M-Right> :bn!<CR>
map <M-Left> :bp!<CR>
share|improve this question
up vote 7 down vote accepted

Vim initialization files are processed in this order (simplified; see :help initialization):

  1. $VIM/vimrc
  2. $HOME/.vimrc
  3. $VIM/gvimrc
  4. $HOME/.gvimrc

The problem is that MacVim maps M-Right and M-Left (and several other key combinations) in its $VIM/gvimrc (i.e. …/; this will override any mappings you have made on those key combinations in $HOME/.vimrc.

If you examine this startup file (i.e. :view $VIM/gvimrc), you will find that these particular mappings can be inhibited by setting the special variable macvim_skip_cmd_opt_movement (to any value) in your $HOME/.vimrc.

let macvim_skip_cmd_opt_movement = 1

This will inhibit ten default MacVim mappings (Command and Option for each of Left, Right, Up, Down, and BS).

Alternatively, you could just put your mappings in your $HOME/.gvimrc (where they will override the default MacVim mappings even if you have not inhibited them with macvim_skip_cmd_opt_movement).

share|improve this answer
Chris, you are awesome!!! Thank you so much!!! – Art Jul 18 '11 at 2:37

Try putting this in your .vimrc file:

" Set left and right option/alt keys to be meta keys
set macmeta

Then try those mappings again and see if they work. If you want to reverse it simply do :set nomacmeta.

If you also use this .vimrc file on computers without MacVim on them use this instead:

" Set left and right option/alt keys to be meta keys
if has("gui_macvim")
    set macmeta
share|improve this answer
I get 'Invalid argument macmeta=rl' error message. If I do ':set macmeta rl' it turns all the text into right-to left view – Art Jul 14 '11 at 6:51
Well you don't want to do ':set macmeta rl' because that is essentially two commands ':set macmeta' and ':set rl' (which you figured out does right to left text). I realize I made a mistake in my original answer now (I couldn't test it because I don't have MacVim). I'll edit it, and see if the new solution works for you. – lyallcooper Jul 14 '11 at 6:56
"set macmeta" unfortunately does not fix it, pressing alt-'->' just makes cursor jump to next word – Art Jul 14 '11 at 23:28
Thanks for the has("gui_macvim") though! – Art Jul 19 '11 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .