Macos – How to let Ctrl + Page Down switch tabs inside Vim in Terminal.app

macmacosshortcutsterminalvim

When running vim inside the Terminal in Ubuntu, I can use Ctrl + Page Up or Page Down to switch between the vim tabs. How do I set up this for Terminal.app or iTerm2 for Mac OS X? I have a Macbook Air (2011) so I don't have 'proper' Page Up and Page Down keys, if that matters.

I have tried to set up various escape codes, but so far nothing works.

EDIT: I don't have privs to answer my own question, but here is the answer:

ANSWER:

I found the correct escape sequences.
In Terminal.app's keyboard settings,

set "control page up" to "send string to shell:", with this value: "\033[5;5~"

set "control page down" to "send string to shell:", with this value: "\033[6;5~"

Best Answer

If you don't have actual pageup and pagedown keys on your keyboard there is no way to map these to anything.

  • <C-PageDown> is an alternative to :tabnext, :tabn and gt.
  • <C-PageUp> is an alternative to :tabprevious, :tabN and gT.

I strongly suggest you use gt and gT instead, they follow Vim's grammar (lowercase letter for "forward commands", uppercase for "backward commands") and so are very easy to memorize.

If you don't like gt/gT you can map them to something more to your taste:

nnoremap <C-Up> gT
nnoremap <C-Down> gt

But I don't think it's necessary.

Your example (a PageUp/PageDown-less keyboard) seems to be a rather nice example of the intelligence of Vim's seemingly weird design decisions.

--EDIT (as per the asker's request)--

I found the correct escape sequences. In Terminal.app's keyboard settings,

set "control page up" to "send string to shell:", with this value: "\033[5;5~"

set "control page down" to "send string to shell:", with this value: "\033[6;5~"