Home » Odeon Blogs » Liviu, Agile Bear »

MacOS vim control+arrow functionality

MacOS vim control+arrow functionality

Note: before doing any of this changes, make sure you back up your expse&spaces settings, terminal keyboard settings and .vimrc.

Being a fan of vim but unliking "gt" and "gT" to switch tabs and being used to do this by Control+arrows, raised a problem on MacOS.
The Linux .vimrc had simple commands:

  1. map <C-Up> :tabnew<CR>
  2. map <C-Down> :q<CR>
  3. map <C-Left> gT
  4. map <C-Right> gt
Obviously this commands didn't worked, first reason because it is used for Expose&Spaces.
So first step, change this shortcuts:
System Preferences > Expose and Spaces > Spaces

Changing it to Control+Option+arrow is good enough.

But this still doesn't fix the problem, because the Control+arrow doesn't reaches to vim. To see how vim interprets a combination of keys, you can press Ctrl+v followed by that combination. The result of this is just the arrow key, like control isn't even pressed.

Luckily mac term allows us to change keyboard settings and we can set it act on control+arrow as we want.
In order to find the correct marking for the action, looking at Xterm Control Sequences sending control means "Esc ["; as for the arrow keys, up=A, down=B, right=C and left=D.
So the keyboard settings will look something like this:


But it still doesnt work.
That's because vim receives this serie of characters: Esc[A
This is where vimrc helps us. Instead of mapping <C-Up> we map <Esc>[A resulting in:
  1. map <Esc>[A :tabnew<CR>
  2. map <Esc>[B :q<CR>
  3. map <Esc>[D gT
  4. map <Esc>[C gt
Enjoy your vim with control+arrows.


Categories: MacVim OS X vim


Tagged as: arrow control control arrow macos osx vim

Discussion

  1. Yoo. You got Mac!
    Welcome to the cult!


  2. Yeah, thanks, got my mac and loving it from day one.


  3. Florin T.PATRASCU on Jul 07, 2011 - 19:44 said:

    hehe, then you should probably check http://www.vicoapp.com/

    Noroc!
    @florin


  4. Nice tut,
    exactly what i was looking for !

    Thx




Leave a Comment :

(required)


(required)




(required)




(required)






Leave a Comment


Page generated in: 0.20s