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. The Tab Bar is a row of tabs—buttons that you can click to switch between window configurations on that frame.
Each tab on the Tab Bar represents a named persistent window configuration. Its name is composed from the list of names of buffers visible 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 Tab Line). Whereas tabs on the Tab Line at the top of each window are used to switch between buffers, tabs on the Tab Bar at the top of each frame are used to switch between window configurations containing several windows with 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-show controls whether the Tab Bar mode is turned on automatically. If the value is
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. The value
nil always keeps the tab bar hidden; in this case it’s still possible to switch between named window configurations without the tab bar by using
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-close, etc.
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.
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 variable
C-x t b bufname RET
bufname in another tab. This runs
C-x t f filename RET
filename and select its buffer in another tab. This runs
find-file-other-tab. See Visiting.
C-x t d directory RET
Select a Dired buffer for directory
directory in another tab. This runs
dired-other-tab. See Dired.
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-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). It 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.
C-x t 1
Close all tabs on the selected frame, except the selected one.
tab-bar-close-tab-select defines what tab to select after closing the current tab. By default, it selects a recently used tab.
tab-undo restores the last closed tab.
The following commands can be used to switch between tabs:
C-x t o
Switch to the next tab. 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 next
nth tab; with a negative argument -
n, it switches back to the previous
Switch to the previous tab. With a positive numeric argument
n, it switches to the previous
nth tab; with a negative argument -
n, it switches back to the next
C-x t RET tabname RET
Switch to the tab by its name, with completion on all tab names. Default values are tab names sorted by recency, so you can use
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. After customizing the variable
tab-bar-select-tab-modifiers to specify a
modifier key, you can select a tab by its ordinal number using the specified modifier in combination with the tab number to select. To display the tab number alongside the tab name, you can customize another variable
tab-bar-tab-hints. This will help you to decide what key to press to select the tab by its number.
Switch to the recent tab. 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:
C-x t r tabname RET
Rename the current tab to
tabname. You can control the programmatic name given to a tab by default by customizing the variable
C-x t m
Move the current tab
n positions to the right with a positive numeric argument
n. With a negative argument -
n, move the current tab
n positions to the left.
You can enable
tab-bar-history-mode to remember window configurations used in every tab, and 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 navigates forward in the history of window configurations.