Keyboard shortcut to jump between tabs on OS X Terminal

123

27

In OS X Terminal.app, if you open new windows, you can easily switch between them with Cmd-1, Cmd-2, Cmd-3, etc.

You can also cycle between tabs, using Cmd-Shift-{ and Cmd-Shift-}. (or Cmd-Shift-Left and Cmd-Shift-Right)

But is there a way to jump straight to a particular tab, like you can with windows? e.g. Cmd-Shift-3 to jump to the third tab? (That's not it, of course.)

I'm pretty sure it's impossible out of the box, but what if I'm willing to write some AppleScript to make this work?

Dan Fabulich

Posted 2010-04-17T01:13:05.403

Reputation: 2 681

4ctrl + tab will nav you thru the terminal tabs in MacOS Sierra (and probably earlier) – SMT – 2017-01-03T17:52:40.337

14Just for reference: Shift-Command-Left/Right Arrow also switch tabs. And in Mac OS X Lion 10.7, you can use a three-finger swipe to switch tabs. – Chris Page – 2011-09-17T10:14:30.410

Three-finger swipe does not work in Mavericks (for me). – SabreWolfy – 2014-02-13T12:05:33.733

<kbd>Cmd</kbd>-<kbd>1</kbd>, etc. do not work in Mavericks. – SabreWolfy – 2014-02-13T12:06:48.083

Answers

12

Ditch Terminal and use iTerm. It lets you do this and is, to me anyway, a bit more useful.

Michael Graff

Posted 2010-04-17T01:13:05.403

Reputation: 486

1Winner! I just installed it and I already love iTerm's configurability (though it is a bit complex...) – Dan Fabulich – 2010-04-19T02:21:12.670

2iTerm is relatively slow in comparison to the regular Terminal. But nonetheless, a good terminal emulator. – schlingel – 2016-06-22T08:29:23.780

9BTW ctrl + tab lets you change which tab you're on in terminal in OSX. – SMT – 2017-01-03T17:51:36.603

3

I would stick with Terminal and learn the below shortcut, iTerms latency is crazy : https://danluu.com/term-latency/

– Adam Fallon – 2017-07-19T14:07:59.947

You can charge the Terminal shorcuts to match iTerm. – William – 2018-08-21T23:14:52.980

Consider using iTerm2, as iTerm 1 didn't get any updates since 2009

– Andrey Semakin – 2020-01-07T08:53:52.417

iTerm2 is v buggy for pasting: after a long struggle I have regrettably reverted to terminal – javadba – 2020-02-01T03:51:14.700

1With iTerm, the answer would be command + T, and control + tab, just like a browser. command + W closes a tab. – Droogans – 2013-05-15T19:13:02.050

195

The key combination is: Shift-Cmd-Left or Right

Ben

Posted 2010-04-17T01:13:05.403

Reputation: 3 798

16With this I no longer have a need for iTerm :) – slott – 2015-02-19T07:06:16.443

9Did the original question not ask for a way to switch to a specific tab (rather than to next or previous tab)? – matty – 2016-06-03T14:16:28.290

6This should be the accepted anwer – Juan Fuentes – 2016-09-20T18:06:25.153

1I was a little taken aback when I thought I would have to have to install iterm just to move between tabs......phew. – Nikhil Sahu – 2017-08-05T09:54:57.920

can we configure it ? – Knight71 – 2018-02-27T09:22:38.460

I can't believe it's easy yet. – Tung – 2019-03-19T22:58:37.417

22

It can be done from System Preferences > Keyboard > Shortcuts > App Shortcuts > click + > select Terminal.app and add the option title as it appears in the Terminal menu, which can be:

  • Select Next Tab (on Mavericks and earlier)
  • Show Next Tab (on Yosemite, El Capitan, Sierra...)

Yosemite menu items

Note: As you probably realize, you can do this with absolutely any [Cocoa] OSX app that has a menu with options, even if originally the app defined no shortcut for the option.

This kind of shortcuts are not equivalent to using native app shortcuts. What OSX is in fact doing is triggering the provided menu option via the label - you'll notice that while you press the keys the corresponding menu item will flash in the menu bar.

After years of resisting the idea of using a third-party terminal i finally switched to iTerm2 primarily because of properly working window split which in the ootb Terminal.app is not very useful. Also the shortcuts are fully configurable, making it possible to achieve anything you want, including switching to a specific tab with +[tab number] to jump to the Nth tab.

ccpizza

Posted 2010-04-17T01:13:05.403

Reputation: 5 372

5Did the original question not ask for a way to switch to a specific tab (rather than to next or previous tab)? – matty – 2016-06-03T14:16:45.573

2@matty: you are right, the original question mentions switching to a specific tab, but the question title is more generic than that, so most people who found this question were just looking for a way to easily switch tabs with an easier shortcut than OSX provides by default. – ccpizza – 2016-06-04T08:46:48.027

9

I've been using Spark for years. It lets you overwrite shortcuts of any application, such as Terminal and Safari. I use it to make both programs switch tabs with command+n where n is the tab number, from 1 to 9.

After you download and copy Spark.app to /Applications, start it, click All Applications' Hotkeys to expand the menu on the left, and click on the plus sign to add new application.

Add Terminal (from /Applications/Utilities/Terminal.app). Next thing is to create the shortcuts: click File->New HotKey->AppleScript (or just hit command+1). Click on the shortcut area and hit command+1, name it tab1 and use this code:

tell front window of application "Terminal" to set selected tab to tab 1

Repeat it for command+2 to command+9. If you want the ability to vertically maximize the terminal, create a new shortcut like command+shift+m, name it whatever you want and use this code:

tell application "Finder"
    set _b to bounds of window of desktop
end tell

tell application "Terminal"
    tell front window
        set {_x, _y, _w, _h} to (get bounds)
        set _vz to item 4 of _b
        set bounds to {_x, 10, _w, _vz}
    end tell
end tell

Same thing for Safari on tab shortcuts, but the code is a bit different:

tell front window of application "Safari" to set current tab to tab 1

Honestly, I can't use either Terminal or Safari without this.

fiorix

Posted 2010-04-17T01:13:05.403

Reputation: 191

1

You can use osacompile to save scripts like this quickly: for n in {1..9} -1; do osacompile -e "try" -e "tell app \"Terminal\" to tell window 1 to set selected tab to tab $n" -e "end" -o Select\ Tab\ $n.scpt; done. Wrapping the scripts in try blocks prevents error dialogs. Spark was last updated in 2008; another application that allows assigning application-specific shortcuts to scripts is FastScripts.

– Lri – 2012-07-16T18:23:07.283

7

In macOS High Sierra (10.13) you can switch to a specific tab using the shortcut keys 19.

To enable/disable these shortcut keys, go to Settings > General and toggle Use ⌘-1 through ⌘-9 to switch tabs.

Terminal Settings > General

Christian Schmidt

Posted 2010-04-17T01:13:05.403

Reputation: 171

4

Lesser known multi-application keyboard shortcuts

Bring the previous tab to the front

Shift-Command-[

Bring the next tab to the front

Shift-Command-]


Origin and scope

If I recall correctly, those were the shortcuts when Safari gained tabs.

Those original shortcuts are not in how-to HT201236 (Mac keyboard shortcuts - Apple Support) but they are in Safari 9 (El Capitan): Safari keyboard and other shortcuts and:

  • both shortcuts are still good with other applications – such as Terminal – in release candidate 16A319 of Mac OS X 10.12 (macOS Sierra).

Graham Perrin

Posted 2010-04-17T01:13:05.403

Reputation: 1 147

2

I arrived here wanting an answer on how to change the shortcut for ANY application. @ccpizza's answer put me in the right direction.

Here's how I did it:

  • Open "System Preferences" (From Apple menu top left corner of screen)
  • Open "Keyboard"
  • Select "App Shortcuts" on the left
  • Press the + sign
  • In the popup, choose "All applications"
  • Enter "Show Next Tab" (without parentheses) and your desired shortcut
  • Enter "Show Previous Tab" and your desired shortcut

You can do this for any menu item (top bar). OSx does a text search, so you just have to match it... And be lucky enough that all apps use the same naming :)

publicJorn

Posted 2010-04-17T01:13:05.403

Reputation: 121

This works nicely. Now it has the same shortcut keys with the browser when I switch between tabs. And the new shortcuts also reflect in the Terminal.app --> Window dropdown. – wenbert – 2019-03-19T22:37:13.933

0

Control+Tab works fine as for now

tworec

Posted 2010-04-17T01:13:05.403

Reputation: 101

0

Tab Switching in Terminal is the only way that I know. I haven't tested it with Snow Leopard so YMMV.

Or you can use Screen and switch "tabs" with Ctrl-A,n and Ctrl-A,p or Ctrl-A, 0-9 to switch directly to one.

Jawa

Posted 2010-04-17T01:13:05.403

Reputation: 3 349

This no longer appears to work in Snow Leopard. – Dan Fabulich – 2010-04-19T02:20:08.740

0

Copied from How can I change the keyboard shortcut for switching tabs in Mac Terminal?

1: Install SIMBL (plugin enabler): http://www.culater.net/software/SIMBL/SIMBL.php

2: Install the TerminalTabSwitching.bundle

git clone https://github.com/dabeeeenster/terminaltabswitching
cp -r terminaltabswitching/TerminalTabSwitching.bundle "/Library/Application Support/SIMBL/Plugins"

3: Restart the Terminal app, and enjoy Cmd+[0-9] tab-switching.

FYI: It you received something like plugin is not verified in terminal version # (a number) when you opened your terminal again, maybe the following information would help.

(1) Open

/Library/Application\ Support/SIMBL/Plugins/Terminal/TerminalTabSwitching.bundle/Contents/Info.plist

using your favorite text editor under sudo.

(2) Search For <key>MaxBundleVersion</key>.

(3) Change <string>280</string> at next line to your terminal version number or higher like <string>300</string>. Save.

(4) Quit terminal and reopen it. Hopefully that prompt would disappear and you can use Cmd+[0:9] for tab switching.

ycz

Posted 2010-04-17T01:13:05.403

Reputation: 3