Tab Bars
On graphical displays and on text terminals, Emacs can optionally display a Tab Bar at the top of each frame, just below the menu bar (Menu Bars) and above or below the tool bar (Tool Bars) depending on the variable tab-bar-position. The Tab Bar is a row of tabs—buttons that you can click to switch between window configurations. Each tab on the Tab Bar represents a named persistent window configuration of its frame, i.e., how that frame is partitioned into windows and which buffer is displayed in each window. The tab's name is composed from the list of names of buffers shown in windows of that window configuration. Clicking on the tab switches to the window configuration recorded by the tab; it is a configuration of windows and buffers which was previously used in the frame when that tab was the current tab. If you are using the desktop library to save and restore your sessions (Saving Emacs Sessions), the tabs from the Tab Bar are recorded in the desktop file, together with their associated window configurations, and will be available after restoring the session. Note that the Tab Bar is different from the Tab Line (Tab Line). Whereas tabs on the Tab Line at the top of each window are used to switch between buffers in the window, tabs on the Tab Bar at the top of each frame are used to switch between window configurations containing several windows showing one or more buffers. To toggle the use of Tab Bars, type M-x tab-bar-mode. This command applies to all frames, including frames yet to be created. To control the use of tab bars at startup, customize the variable tab-bar-mode and save your customization. The variable tab-bar-show controls whether the Tab Bar mode is turned on automatically. If the value is t, then tab-bar-mode is enabled when using the commands that create new tabs. The value 1 hides the tab bar when it has only one tab, and shows it again when more tabs are created. More generally, a value that is a non-negative integer causes the Tab Bar to be displayed only if the number of tabs is greater than that integer. The value nil always keeps the Tab Bar hidden; in this case it's still possible to switch between named window configurations without displaying the Tab Bar by using M-x tab-next, M-x tab-switcher, and other commands that provide completion on tab names. Also it's possible to create and close tabs without the Tab Bar by using commands M-x tab-new, M-x tab-close, etc. Note that a numerical value of tab-bar-show can cause the Tab Bar to be displayed on some frames, but not on others, depending on the number of tabs created on each frame. To toggle the use of the Tab Bar only on the selected frame, type M-x toggle-frame-tab-bar. This command facilitates selectively enabling the Tab Bar on some frames while keeping it disabled on others, irrespective of the values of tab-bar-mode and tab-bar-show. The prefix key C-x t is analogous to C-x 5. Whereas each C-x 5 command pops up a buffer in a different frame (Creating Frames), the C-x t commands use a different tab with a different window configuration in the selected frame. The various C-x t commands differ in how they find or create the buffer to select. The following commands can be used to select a buffer in a new tab:
- C-x t 2
- Add a new tab (
tab-new). You can control the choice of the buffer displayed in a new tab by customizing the variabletab-bar-new-tab-choice. You can control the names given by default to new tabs by customizing the variabletab-bar-tab-name-function. -
C-x t b bufname
RET - Select buffer bufname in another tab. This runs
switch-to-buffer-other-tab. -
C-x t f filename
RET - Visit the file filename (Visiting) and select its buffer in another tab. This runs
find-file-other-tab. -
C-x t d directory
RET - Edit the specified directory (Dired) in another tab. This runs
dired-other-tab. - C-x t t
- This is a prefix command (
other-tab-prefix) that affects the next command invoked immediately after this prefix command. It requests the buffer displayed by the next command to be shown in another tab.
By default, a new tab starts with the buffer that was current before calling the command that adds a new tab. To start a new tab with other buffers, customize the variable tab-bar-new-tab-choice. The variable tab-bar-new-tab-to defines where to place a new tab. By default, a new tab is added on the right side of the current tab. The following commands can be used to delete tabs:
- C-x t 0
- Close the selected tab (
tab-close). This has no effect if there is only one tab, unless the variabletab-bar-close-last-tab-choiceis customized to a non-default value. - C-x t 1
- Close all tabs, except the selected tab, on the selected frame.
The variable tab-bar-close-tab-select defines what tab to select after closing the current tab. By default, it selects a recently used tab. The command tab-undo restores the last closed tab. The following commands can be used to switch between tabs:
-
C-x t o, C-
TAB - Switch to the next tab (
tab-next). If you repeat this command, it cycles through all the tabs on the selected frame. With a positive numeric argument n, it switches to the n/th next tab; with a negative argument -/n, it switches back to the /n/th previous tab. -
S-C-
TAB - Switch to the previous tab (
tab-previous). With a positive numeric argument n, it switches to the n/th previous tab; with a negative argument -/n, it switches to the /n/th next tab. -
C-x t
RETtabnameRET - Switch to the tab by its name (
tab-switch), with completion on all tab names. The default value and the ``future history'' of tab names is sorted by recency, so you can useM-n(next-history-element) to get the name of the last visited tab, the second last, and so on. - modifier-tab-number
- Switch to the tab by its number tab-number (
tab-select). After customizing the variabletab-bar-select-tab-modifiersto specify one or more modifier keys, you can select a tab by its ordinal number using one of the specified modifiers in combination with the tab number to select. The number 9 can be used to select the last tab. You can select any modifiers supported by Emacs, Modifier Keys. To display the tab number alongside the tab name, you can customize another variabletab-bar-tab-hints. This will help you decide which numerical key to press to select the tab by its number. -
modifier-
9 - Switch to the last tab (
tab-last). The key combination is the modifier key defined bytab-bar-select-tab-modifiersand the key9. With a numeric argument n, switch to the /n/th last tab. -
modifier-
0 - Switch to the recent tab (
tab-recent). The key combination is the modifier key defined bytab-bar-select-tab-modifiersand the key0. With a numeric argument n, switch to the /n/th recent tab.
The following commands can be used to operate on tabs:
-
C-x t r tabname
RET - Rename the current tab to tabname (
tab-rename). - C-x t m
- Move the current tab one position to the right (
tab-move). With a positive numeric argument n, move it that many positions to the right; with a negative argument -n, move it n positions to the left.
You can use the mouse to operate on tabs. Clicking mouse-2 closes the tab. Clicking mouse-3 pops up the context menu with the items that operate on the clicked tab. Dragging the tab with mouse-1 moves it to another position on the tab bar. Mouse wheel scrolling switches to the next or previous tab. Holding down the SHIFT key during scrolling moves the tab to the left or right. Touch screen input (Other Input) can also be used to operate on tabs. Long-pressing (Touchscreens) a tab will display a context menu with items that operate on the tab that was pressed, and long-pressing the tab bar itself will display a context menu which lets you create and remove tabs; tapping a tab itself will result in that tab's window configuration being selected, and tapping a button on the tab bar will behave as if it was clicked with mouse-1. You can enable tab-bar-history-mode to remember window configurations used in every tab, and later restore them.
- M-x tab-bar-history-back
- Restore a previous window configuration used in the current tab. This navigates back in the history of window configurations.
- M-x tab-bar-history-forward
- Cancel restoration of the previous window configuration. This moves forward in the history of window configurations.
It's possible to customize the items displayed on the tab bar by the user option tab-bar-format.