Linux/tmux: Difference between revisions

From Omnia
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
== usage ==
== tmux ==
 
== Introduction to tmux ==
 
https://www.redhat.com/en/blog/introduction-tmux-linux


== converting from screen to tmux ==
== converting from screen to tmux ==
Line 5: Line 9:
"Navigating in tmux after using GNU screen requires adjusting to one fundamental change: the default prefix shortcut is Ctrl+b instead of Ctrl+a. However, the core concept of navigating windows remains remarkably similar, while managing "panes" (splits) is significantly easier in tmux." <ref>https://medium.com/@yiskylee/gnu-screen-and-tmux-which-should-you-choose-de325d32fc2a</ref>
"Navigating in tmux after using GNU screen requires adjusting to one fundamental change: the default prefix shortcut is Ctrl+b instead of Ctrl+a. However, the core concept of navigating windows remains remarkably similar, while managing "panes" (splits) is significantly easier in tmux." <ref>https://medium.com/@yiskylee/gnu-screen-and-tmux-which-should-you-choose-de325d32fc2a</ref>


=== screen to tmux ===
<markdown>
| function | screen | tmux |
| --- | --- | --- |
| Start a new session with session name | `screen -S session_name` | `tmux new -t session_name` |
| Create a new window | `Ctrl+a c` | `Ctrl+b c` |
| Switch to next window | `Ctrl+a n` | `Ctrl+b n` |
| Switch to previous window | `Ctrl+a p` | `Ctrl+b p` |
| Reattach to a session | `screen -r process_id/session_name` | `tmux a -t process_id/session_name` |
| Rename session name | `Ctrl+a :sessionname session_name` | `Ctrl+b $` |
| Split window vertically | `Ctrl+a |` | `Ctrl+b %` |
|  |  | |
| Navigate Windows | `Ctrl+a Tab` | `Ctrl+b ArrowKey` |
| List Sessions | screen -ls | tmux ls |
| Rename window | `Ctrl+a A` | `Ctrl+b ,` |
| Rename window command | `Ctrl+a : title "name name"` | `Ctrl+b : rename-window new-name` |
| List Windows | `Ctrl+a "` | `Ctrl+b w` |
| Search Windows | ? | `Ctrl+b f` |
| Reattach to single session | `screen -x` | `tmux a` |
</markdown>
<ref>https://gist.github.com/yiskylee/e4bc72669f46d3cd92cc8a605542d904#file-screen_tmux_commands-csv</ref>
=== Set Ctrl+b to Ctrl+a ===
If you are comfortable with the screen trigger: <ref>https://medium.com/@yiskylee/gnu-screen-and-tmux-which-should-you-choose-de325d32fc2a</ref>
<pre>
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
</pre>
=== Navigation ===
Ctrl+b ArrowKey  # switch between windows


== ~/.tmux.conf ==
== ~/.tmux.conf ==

Latest revision as of 22:22, 3 September 2026

tmux

Introduction to tmux

https://www.redhat.com/en/blog/introduction-tmux-linux

converting from screen to tmux

"Navigating in tmux after using GNU screen requires adjusting to one fundamental change: the default prefix shortcut is Ctrl+b instead of Ctrl+a. However, the core concept of navigating windows remains remarkably similar, while managing "panes" (splits) is significantly easier in tmux." [1]

screen to tmux

function screen tmux
Start a new session with session name screen -S session_name tmux new -t session_name
Create a new window Ctrl+a c Ctrl+b c
Switch to next window Ctrl+a n Ctrl+b n
Switch to previous window Ctrl+a p Ctrl+b p
Reattach to a session screen -r process_id/session_name tmux a -t process_id/session_name
Rename session name Ctrl+a :sessionname session_name Ctrl+b $
Split window vertically Ctrl+a | Ctrl+b %
Navigate Windows Ctrl+a Tab Ctrl+b ArrowKey
List Sessions screen -ls tmux ls
Rename window Ctrl+a A Ctrl+b ,
Rename window command Ctrl+a : title "name name" Ctrl+b : rename-window new-name
List Windows Ctrl+a " Ctrl+b w
Search Windows ? Ctrl+b f
Reattach to single session screen -x tmux a

[2]

Set Ctrl+b to Ctrl+a

If you are comfortable with the screen trigger: [3]

unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Navigation

Ctrl+b ArrowKey   # switch between windows

~/.tmux.conf

Converted from my screen#.screenrc

$ cat ~/.tmux.conf
# My tmux Configuration - $HOME/.tmux.conf
# Converted from $HOME/.screenrc

# ---------------------------------------------------------------------------
# Prefix - match screen's ctrl+a instead of tmux's default ctrl+b
# ---------------------------------------------------------------------------
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# ---------------------------------------------------------------------------
# autodetach on
#   No equivalent needed: the tmux server always keeps sessions alive when the
#   client's terminal goes away. Clients detach rather than kill the session.
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# startup_message off
#   No equivalent needed: tmux has no startup banner.
# ---------------------------------------------------------------------------

# 10,000 lines of scrollback!  (screen: defscrollback 10000)
set -g history-limit 10000

# flash screen on bell  (screen: vbell on / vbell_msg)
set -g visual-bell on
set -g bell-action any
set -g monitor-bell on

# clear scrollback with '[ctrl]+a C'  (screen: bind C eval "scrollback 0" ...)
#   NOTE: tmux 3.2+ binds C to customize-mode by default; this overrides it.
bind C send-keys -R \; clear-history \; display-message "scrollback cleared"

# set default terminal  (screen: term linux)
#   Deliberate deviation: "linux" would cost tmux 256 colors, italics and
#   extended keys. Use "screen-256color" instead if tmux-256color is missing.
set -g default-terminal "tmux-256color"
#set -g default-terminal "screen-256color"

# set default title  (screen: shelltitle ".")
#   tmux renames the window after the running command automatically.
set -g automatic-rename on
set -g automatic-rename-format "#{b:pane_current_command}"
set -g set-titles on
set -g set-titles-string "#T"

# set default shell  (screen: shell /bin/bash)
set -g default-shell /bin/bash

# ---------------------------------------------------------------------------
# hard line status  (screen: hardstatus alwayslastline
#   "%{= KW} %H %{= Kw}|%{-} %-w%{= bW}%n%f %t%{-}%+Lw")
# ---------------------------------------------------------------------------
set -g status on
set -g status-position bottom
set -g status-justify left
set -g status-interval 5

# %{= KW} - dim-grey text on a bright-white bar
set -g status-style "fg=brightblack,bg=brightwhite"

# %H | - hostname followed by a separator
set -g status-left " #H #[fg=brightblack,bg=white]|#[default] "
set -g status-left-length 40
set -g status-right ""

# %n%f %t - window number, flags, title
setw -g window-status-format "#I#F #W"
setw -g window-status-style "fg=brightblack,bg=brightwhite"

# %{= bW} - current window in blue on bright white
setw -g window-status-current-format "#I#F #W"
setw -g window-status-current-style "fg=blue,bg=brightwhite,bold"
setw -g window-status-separator " "

# go to home dir  (screen: chdir)
#   tmux inherits the active pane's cwd, so force $HOME explicitly.
bind c new-window -c "$HOME"
bind '"' split-window -v -c "$HOME"
bind % split-window -h -c "$HOME"

# ---------------------------------------------------------------------------
# look and feel  (screen: commented-out caption/hardstatus alternates)
# ---------------------------------------------------------------------------
#set -g status-right "%H:%M %a %Y-%m-%d "
#set -g status-right-length 40
#set -g status-position top

keywords