Navigating Tabs With The Keyboard for MacVim and Other Apps on OS X
I use MacVim as my primary editor and since it uses hjkl
as arrow keys and have gotten used to h
and l
representing left and right respectively. I prefer to use the keyboard over the trackpad (or mouse) wherever possible, so I wanted to replicate using these keys as closely as possible for working tabs.
MacVim has tabs, so what better than to start with that? In .vimrc
, I map Ctrl-h
and Ctrl-l
to gT
and gt
respectively:
:map <c-h> <Esc>gT
:map <c-l> <Esc>gt
OS X allows you to configure and override keyboard shortcuts for menu items for any app. In System Preferences.app
> Keyboard
> Shortcuts
. Under All Applications
, I add shortcuts for Select Previous Tab
, Previous Tab
and Show Previous Tab
, assigning them all to Ctrl-H
. I add Ctrl-L
for Show Next Tab
, Next Tab
and Select Next Tab
. These shortcuts cover as least Safari, Chrome, Finder, HipChat, Terminal (and iTerm).
I also add app-specific shortcuts — Select Previous Conversation
and Select Next Conversation
for Messages.app, Previous Chat
and Next Chat
for Adium.app.
With this setup, I can use h-l
as left and right when I’m editing a file in MacVim, use Ctrl-h
and Ctrl-l
to switch tabs both in MacVim and in most other OS X apps.