9

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

2 Answers 2

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

5
  • 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
    Commented Aug 14, 2011 at 13:29
  • The MBA simulates PageUp and PageDown with <function key> and ArrowUp / ArrowDown
    – ramn
    Commented Aug 14, 2011 at 13:30
  • OK, I've edited my answer. But I think you could POST an answer, don't you?
    – romainl
    Commented Aug 14, 2011 at 16:36
  • 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
    Commented Aug 14, 2011 at 17:23
  • Since I had to search for it: the \033 part of the string needs be generated by Esc+[ .
    – Konrad
    Commented Dec 6, 2017 at 10:51
10

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~

You must log in to answer this question.

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