10

I've recently started using a Mac (running Lion), and there is one inconsistency that's getting to me.

In Chrome and MVim, I can switch tabs with Ctrl+PageUp/PageDown. But, in the Terminal, I have to use Cmd+Shift+Left/Right.

I'd like to change the latter to Ctrl+PageUp/PageDown, but I can't seem to do this.

When I go into System Preferences → Keyboard → Keyboard Shortcuts → Application Shortcuts, and add a shortcut to Terminal's "Select Next Tab", I can set it to be pretty much anything as long as it does not include a PageUp/PageDown key.

Why is there such a limitation, and can I get around it?

5 Answers 5

8

defaults write -g NSUserKeyEquivalents -dict-add "Select Previous Tab" "^\UF72C" "Previous Tab" "^\UF72C" "Previous Workspace" "^\UF72C" "Select Next Tab" "^\UF72D" "Next Tab" "^\UF72D" "Next Workspace" "^\UF72D"

-g modifies ~/Library/Preferences/.GlobalPreferences.plist. You need to reopen apps to apply changes, and the manually added shortcuts aren't displayed in Application Shortcuts.

6
  • Before I try it, how would I undo this? Is there something like -dict-remove? (Also, I'd love to know how you found this solution.)
    – foxcub
    Sep 13, 2011 at 4:07
  • 1
    defaults delete -g NSUserKeyEquivalents. You can also edit the file manually with: f=~/Library/Preferences/.GlobalPreferences.plist; plutil -convert xml1 $f; open $f. I didn't find out about it from anywhere in particular.
    – Lri
    Sep 13, 2011 at 5:39
  • I think the key codes are wrong. It tries to set everything to be Ctrl+PageUp. Where can I lookup these codes?
    – foxcub
    Sep 13, 2011 at 16:43
  • Sorry, fixed it. lri.me/chars
    – Lri
    Sep 14, 2011 at 0:37
  • Accepting this answer, since it's a more direct approach to my question. (Sorry that I can't upvote it -- not enough reputation.)
    – foxcub
    Sep 14, 2011 at 1:15
3

You could use iTerm, since that has a much more flexible shortcuts system, but you will inevitably come across another application that does not work the way you want.

I think you will find that Command+shift+[ and Command+shift+] are the only consistent shortcuts for switching between tabs and it is better to simply change your habits.

4
  • Is there a way to change Chrome shortcut for switching tabs to the same? (I think I know how to do it for MVim.) I'm Ok with changing my habits, but I need consistency.
    – foxcub
    Sep 10, 2011 at 16:08
  • Chrome already uses those shortcuts, as does MacVim and every other application I have used, except for Adium. Sep 11, 2011 at 0:46
  • Shift-Command-Left/Right Arrow also switch tabs in Terminal. Also, as of Mac OS X Lion 10.7, the "three-finger swipe" gesture switches tabs (as long as you don't have the system preference set to use three-finger swipe for something else).
    – Chris Page
    Sep 13, 2011 at 20:16
  • Note that for people with (many) non-English keyboard layouts, any shortcuts involving keys like [ ] { } are hard to type. That's why I personally much prefer shortcuts that use keys that aren't dependent on keyboard layout. Like PageUp and PageDown.
    – tml
    Dec 27, 2012 at 10:33
3

Lri's answer works (and FWIW, I upvoted it), but takes a bit of a shotgun approach: it creates global settings (instead of Terminal-specific settings), and some of the things it sets actually have no effect on Terminal at all -- I actually don't know what they're for.

If, like me, you're a bit paranoid and would prefer a more "surgical" approach, here's a modified version of Lri's answer:

defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "Select Previous Tab"    "^\UF72C"
defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "Select Next Tab"        "^\UF72D"

This adds only two keybindings, ^PageUp and ^PageDown, and adds them only to Terminal.

2
  • Any idea if this should still work (in El Capitan) ? It's not working for me unfortunately.
    – Chris
    Apr 15, 2016 at 23:51
  • @Chris Looks like you are correct. This no longer seems to work! For one thing, the menus items have changed names (They are now say "Show" instead of "Select), but even correcting for that this setting doesn't seem to have any effect. I actually can't seem to get NSUserKeyEquivalents to work for Terminal at all in El Capitan. Ugh Apr 16, 2016 at 2:47
1

Based on this answer here's a version of this for macOS High Sierra:

defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "Show Next Tab" "^\UF72D"
defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "Show Previous Tab" "^\UF72C"
2
  • 1
    Confirmed that this works on Mojave, though this answer seems to be a duplicate of Laurence Gonsalves' answer. Also, PSA: remember to restart Terminal after running.
    – RACKGNOME
    Jan 6, 2020 at 20:22
  • Thanks for the tip on restarting terminal. I thought none of these solutions were working, but it turned out I just had to restart terminal, doh!
    – user207863
    Apr 1, 2022 at 13:40
0

Still works for MacOS Sonoma (14.0):

defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "Show Next Tab" "^\UF72D"
defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "Show Previous Tab" "^\UF72C"
1

You must log in to answer this question.

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