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

7

7

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~"

ramn

Posted 2011-08-14T12:49:26.170

Reputation: 175

Answers

9

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~"

romainl

Posted 2011-08-14T12:49:26.170

Reputation: 19 227

Since I had to search for it: the \033 part of the string needs be generated by Esc+[ . – Konrad – 2017-12-06T10:51:53.563

Hi, I cant answer my own question it seems, but I found the escape sequences that made it work. Could you perhaps include them in your answer? Thanks (If you do I will accept it :) – ramn – 2011-08-14T13:29:08.707

The MBA simulates PageUp and PageDown with <function key> and ArrowUp / ArrowDown – ramn – 2011-08-14T13:30:03.370

OK, I've edited my answer. But I think you could POST an answer, don't you? – romainl – 2011-08-14T16:36:20.363

romainl: The privilege system didn't allow me to post an answer to my own question, I'm a new user here.

Thanks for your answer and help! – ramn – 2011-08-14T17:23:02.757

5

Based on ramn's answer and just as a reference, this is how to solve this problem in iTerm2:

  1. Go to iTerm / Preferences... / Profiles / Keys
  2. Press the + button to add a profile shortcut
  3. Use shortcut: ^Page Up, action: "Send Escape sequence", value [5;5~
  4. Use shortcut: ^Page Down, action: "Send Escape sequence", value [6;5~

elaichi

Posted 2011-08-14T12:49:26.170

Reputation: 151