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 (see Menu Bars) and above or below the tool bar (see 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 (see 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 (see Window 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 allows to enable the
display of the Tab Bar on some frames and disable it on others,
regardless 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 (see 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:
Add a new tab (tab-new
). You can control the choice of the
buffer displayed in a new tab by customizing the variable
tab-bar-new-tab-choice
. You can control the names given by
default to new tabs by customizing the variable
tab-bar-tab-name-function
.
Select buffer bufname in another tab. This runs
switch-to-buffer-other-tab
.
Visit the file filename (see Visiting Files) and select its buffer
in another tab. This runs find-file-other-tab
.
Edit the specified directory (see Dired, the Directory Editor) in another tab.
This runs dired-other-tab
.
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:
Close the selected tab (tab-close
). This has no effect if there
is only one tab, unless the variable tab-bar-close-last-tab-choice
is customized to a non-default value.
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:
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 nth next tab; with
a negative argument −n, it switches back to the nth
previous tab.
Switch to the previous tab (tab-previous
). With a positive
numeric argument n, it switches to the nth previous tab;
with a negative argument −n, it switches to the
nth next tab.
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 use M-n
(next-history-element
) to get the name of the last visited tab,
the second last, and so on.
Switch to the tab by its number tab-number (tab-select
).
After customizing the variable tab-bar-select-tab-modifiers
to
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,
see Modifier Keys. To display the tab number alongside the tab
name, you can customize another variable tab-bar-tab-hints
.
This will help you decide which numerical key to press to select the
tab by its number.
Switch to the last tab (tab-last
). The key combination is
the modifier key defined by tab-bar-select-tab-modifiers
and
the key 9. With a numeric argument n, switch to the
nth last tab.
Switch to the recent tab (tab-recent
). The key combination is
the modifier key defined by tab-bar-select-tab-modifiers
and
the key 0. With a numeric argument n, switch to the
nth recent tab.
The following commands can be used to operate on tabs:
Rename the current tab to tabname (tab-rename
).
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.
You can enable tab-bar-history-mode
to remember window
configurations used in every tab, and later restore them.
Restore a previous window configuration used in the current tab. This navigates back in the history of window configurations.
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
.