Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
    
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 Aug 14 '11 at 13:29
    
The MBA simulates PageUp and PageDown with <function key> and ArrowUp / ArrowDown –  ramn Aug 14 '11 at 13:30
    
OK, I've edited my answer. But I think you could POST an answer, don't you? –  romainl Aug 14 '11 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 Aug 14 '11 at 17:23
add comment

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~
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.