Tmux - work cases and tune up
Tmux - work cases and tune-up
- how to scroll rows in tmux terminal splited windows
- how to save sessions, layout, dirs and even progs state in tmux
- how to change horizontal split to vertical split in tmux
- how to add horizontal and vertical splits in tmux + key bindings
- how to exit tmux but leave session working
- how to attach session to tmux
- how to know how many sessions you have
- how to kill sessions
- how to swith-between sessions
- how to rename sessions and panes (panes are small part of the window - splatted in tmux)
- How to reload tmux configuration from tmux
For those who don't aware what is it - this is terminal shell and you can install it for your distro like sudo apt-get install tmux (for Debian like Ubuntu etc.)
1. How to scroll rows in tmux terminal spitted windows
To scroll rows within a specifictmuxsplit window (pane), you must first enter copy mode. This allows you to navigate and review the pane's scrollback buffer.Scrolling with Keyboard
- Enter copy mode: Press your
tmuxprefix (default is Ctrl+b), then immediately press the [ key. An indicator in the top right of the pane will show the current line number. - Scroll:
- Use the arrow keys (↑ and ↓) to move one line at a time.
- Use Page Up and Page Down (or Shift+Page Up/Shift+Page Down in some terminal emulators) to jump an entire page.
- Exit copy mode: Press the q key or Esc to return to normal mode.
Scrolling with Mouse
For those who prefer using the mouse wheel, you need to enable mouse mode in your
~/.tmux.conf configuration file. - Edit your
~/.tmux.conffile with an editor likenanoorvim. - Add the following line (for tmux versions 2.1 and up):For older versions, use
set -g mouse onset -g mode-mouse on. - Reload your
tmuxconfiguration using the command line within atmuxsession:- Press the prefix Ctrl+b.
- Type
:to enter thetmuxcommand prompt. - Type
source-file ~/.tmux.confand press Enter.
- Scroll: You should now be able to use your mouse scroll wheel directly within any pane, even in split windows. This also enables clicking to select panes and resize them with the mouse.
--------------------------------------
2 . To save a tmux layout,
the recommended method is to use the tmux-resurrect plugin, as tmux does not have a built-in feature for saving sessions to a file by default. Using the
tmux-resurrect PluginThe
tmux-resurrect plugin saves all session details, including window and pane layouts, current working directories, and even running programs, to a file that can be restored later. 1. Installation (using Tmux Plugin Manager - TPM)
Install TPM first if you don't have it. Instructions can be found on the TPM GitHub page.
Add the
tmux-resurrectplugin to your~/.tmux.conffile:
set -g @plugin 'tmux-plugins/tmux-resurrect'
Run the plugin manager by pressingprefix + I(capital I, whereprefixisCtrl + bby default) inside atmuxsession to fetch and source the plugin.
2. Saving the Layout
To manually save your currenttmuxenvironment, pressprefix + Ctrl + s.A notification message'tmux environment saved'will briefly appear in the status bar.
3. Restoring the Layout
To restore the last saved environment, pressprefix + Ctrl + r.The saved sessions, windows, and pane layouts will be restored.
Alternative Methods
Automatic Saving/Restoring: For continuous, automatic saving (e.g., every 15 minutes) and automatic restoration on startup, you can use the complementarytmux-continuumplugin alongsidetmux-resurrect.Addset -g @plugin 'tmux-plugins/tmux-continuum'to your~/.tmux.conf
and press
prefix + Ito install it.
Scripting: You can also write a custom bash script that usestmuxcommands to recreate a specific, predefined layout.
The
list-windowscommand can display layout data that you can use in your scripts.
Tmuxinator/Tmuxp: For project-specific layouts defined in YAML files, tools like Tmuxinator or Tmuxp can be used to launch predefined workspaces with a single command.
--------------------------------------------------------------
3. how to change horizontal split to vertical split in tmux
You can change an existing horizontal split to a vertical split in tmux by cycling through the preset layouts with a keyboard shortcut or by using theselect-layoutcommand. There is no direct command to "transpose" an existing single horizontal split to a single vertical one while keeping the same panes.Method 1: Cycle through preset layoutsThe quickest method is to use the default keybinding to cycle through the available window layouts. This will rearrange your panes into one of the predefined configurations, includingeven-horizontalandeven-vertical.
- Press your prefix key (by default,
Ctrl + b). - Press the spacebar (
Space).
Repeat this until you reach the desired vertical layout.Method 2: Use a specific preset layout commandIf you want to apply a specific layout immediately, you can use a command or a keybinding that targets a particular preset. The default bindings for these are often mapped toAlt(orMeta) keys combined with numbers.
- Press your prefix key (
Ctrl + B), release, and then pressAlt + 2to arrange panes in an even-vertical layout. - Alternatively, you can access the tmux command prompt:
- Press your prefix key (
Ctrl + b). - Press the colon key (
:). - Type
select-layout even-verticaland pressEnter orselect-layout even-horizontal.
- Press your prefix key (
Method 3: Move a pane to create a vertical split (for specific cases)If you have a complex layout and want more control over which pane goes where, you can move specific panes. This is more involved and generally requires using the command line within tmux.
- Identify pane numbers: Press your prefix key
Ctrl + band thenQto briefly display pane numbers. - Use
swap-pane: For example, to swap the current pane's position with an "up" or "down" pane in the index order, press your prefix keyCtrl + bfollowed by{or}.
For a full explanation of advanced options, including how to configure custom key bindings in your~/.tmux.conffile, you can consult the tmux man page.
--------------------------------------
4. how to add horizontal and vertical splits in tmux + key bindings
Tmux Split Pane Keybindings
- Vertical Split (Side-by-Side): Press
Ctrl + bthen%. - Horizontal Split (Top/Bottom): Press Ctrl + b then
". - Close Current Pane: Press
Ctrl + bthenx. - Switch Between Panes: Press
Ctrl + bthen arrow keys. - Toggle Layouts: Press
Ctrl + bthen Space to cycle through layout arrangements.
Command Line AlternativesYou can also run these commands directly in your terminal or via thetmuxcommand prompt (Ctrl + bfollowed by:):
- Vertical:
tmux split-window -v. - Horizontal:
tmux split-window -h.
Customizing Key bindingsTo make splits more intuitive (e.g., using|for vertical and-for horizontal), add these to your~/.tmux.conffile:creating new windows:bind | split-window -hbind - split-window -vchanging the layout (evenly - all windows will be in the same size!):bind H select-layout even-horizontalbind V select-layout even-verticalaccidentally i found similar article on LinkedInaccidentally i found similar article on LinkedIn link
5. How to exit tmux but leave session workingPress Ctrl + b then d
6 . How to attach session to tmuxin console type tmux attach if you have only one session or
tmux attach -t <session_number>
7. How to know how many sessions you have
type in console tmux list-sessions
8. How to kill sessions
- Press your prefix key, then type
:kill-sessionand pressEnter. - Alternatively, you can press the prefix key followed by
&This prompts for confirmation to close the current window, which in turn kills the session if it's the last window.
Kill a specific session (by name/number) from your current session:
- Press your prefix key, then type
:This opens the tmux command prompt. - Type
kill-session -t <session-name>and pressEnter. - First, you may want to list sessions to find the exact name/number using the command
:list-sessionsor the shortcutPrefix + s.
Kill all other sessions except the current one:
- Press your prefix key, then type
: - Type
kill-session -aand pressEnter
Pressing C-b & prompts for confirmation then kills (closes) the current window. All panes in the window are killed at the same time.
C-b x kills only the active pane. These are bound to the kill-window and kill-pane commands.
9. How to switch between sessions
Navigate between sessions using keybindings:
- Press
Prefix + sto open an interactive menu showing all sessions, windows, and panes. Use arrow keys to navigate and pressEnterto switch.- Press
Prefix + (to switch to the previous session.- Press
Prefix + )to switch to the next session.- Press
Prefix + L(capital L) to switch to the last used session, functioning like an "alt-tab" for sessions.
Switch to a specific session by name:
- Press your prefix key, then type
:- Type
switch-client -t <session-name>and pressEnter
10. How to rename sessions and panes (panes are small part of the window - splatted in tmux)
Naming Sessions and Panes1. Use these commands or shortcuts to provide descriptive names:
- Rename a Session:
- Shortcut: Press
Prefix+$. - Command: Use
tmux rename-session -t current_name new_namefrom the shell.
- Shortcut: Press
- Rename a Pane:
- Command: Enter
Prefix+:then typeselect-pane -T "your_pane_name". - Enable Display: To actually see these names, you must enable pane borders in your
~/.tmux.conf:set -g pane-border-status top set -g pane-border-format " [ #P #T ] "Use code with caution. - Note: Some shells or programs may overwrite these titles automatically.
- Command: Enter
2. Switching InteractivelyThe most efficient way to switch between named items is through the built-in tree view:
- Interactive Tree View: Press
Prefix+w.- This opens a navigable list of all sessions, windows, and panes.
- Use Arrow Keys or j/k to move through the list.
- Press Enter to jump to the selected pane.
- Display Pane Numbers: Press
Prefix+q. Large numbers will appear briefly over each pane; type the corresponding number to jump to it instantly.
3. Switching by Name
- Sessions: Use
Prefix+sto show an interactive session-only list, or usetmux switch-client -t session_namefrom the command prompt. - Windows: Use
Prefix+fto search for a window by its name.
11. How to reload tmux configuration from tmux
1. From within a tmux session
- Enter command mode: Press the prefix key (by default,
Ctrl+b). - Type the command: Press
:(colon) to bring up the command prompt at the bottom of the screen. - Execute the source command: Type
source-file ~/.tmux.conf(orsource ~/.tmux.confin most modern versions) and pressEnter.
2. From your shell/terminal (outside of tmux)Run the following command in your terminal prompt:
tmux source-file ~/.tmux.conf
Additional useful keybindings (add them in .tmux.conf):Quick-Toggle Pane Titles:bind b set-option -g pane-border-status
Renaming pane without typing command in command line:
bind-key T command-prompt -p "Pane Title:" "select-pane -T '%%'"
To reload ~/.tmux.conf file quickly
bind r source-file ~/.tmux.conf \; display "Config reloaded!"

Comments