TMUX

Basics

<prefix> means Ctrl+b

Outside TMUX Session

To do?commands
create session and attachtmux
create session foo and attachtmux new -s foo
create detached session footmux new -s foo -d
list sessionstmux ls
attachtmux attach
detach (inside tmux session)<prefix>+d
attach to session footmux attach -t foo
kill session footmux kill-session -t foo
send multiplexer command to session footmux command -t foo
run ls in session footmux send-keys -t foo 'ls' C-m
run emacs in new windowtmux new-window emacs
  • You can also use the first letter of the Tmux’s argument. For example, tmux a is an alias of tmux attach.

Window Handling

Taskcommands
New window<prefix>+c
Next window<prefix>+n
List all windows<prefix>+w
Rename a window<prefix>+,
Previous window<prefix>+p
Find a window<prefix>+f
Kill a window<prefix>+&
Swap window<prefix>+<

Pane Handling

Taskcommands
Split panes vertically<prefix>+%
Split panes horizontally<prefix>+"
Toggle last active pane<prefix>+;
Swap panes<prefix>+o
Kill pane<prefix>+x
Show pane numbers<prefix>+q
Move pane left<prefix>+{
Move pane right<prefix>+}
Switching between panes<prefix>+<arrow keys>
To resize the paneHold the <prefix>+<arrow keys>
Scroll the pane<prefix>+[
Scroll jumpAlt+<up down arrow keys>

Extra

Tips and Tricks

  • Rename the pane
    printf '\033]2;%s\033\\' 'title goes here'
    

My .tmux.conf

######################
### tmux configs   ###
######################

# Using xterm colour notation
# find at https://jonasjacek.github.io/colors/

# To use the emacs theme color presets while using tmux add this: "export TERM=xterm-256color" in .zshrc
# https://stackoverflow.com/questions/7617458/terminal-emacs-colors-only-work-with-term-xterm-256color
set -g default-terminal "xterm-256color"
# To change the prefix
#set -g prefix C-a

# loud or quiet?
#set -g visual-activity off
#set -g visual-bell off
#set -g visual-silence off
#setw -g monitor-activity off
#set -g bell-action none

#  modes
#setw -g clock-mode-colour colour5
#setw -g mode-style 'fg=colour1 bg=colour18 bold'

# panes
#set -g pane-border-style 'fg=colour19 bg=colour0'
#set -g pane-active-border-style 'bg=colour0 fg=colour9'

# statusbar
# ---------
# To make status bar visible or not?
bind-key -n C-F3 set-option -g status #Ctrl+F3 Combo
set -g status-position top
set -g status-justify left
#set -g status-style fg=colour136,bg=colour235
set -g status-style bg=colour235
set -g status-left ''
set -g status-right '#[fg=colour233,bg=colour8] %Y/%m/%d | %H:%M:%S '
set -g status-right-length 50
set -g status-left-length 20

# Current window which I'm now
setw -g window-status-current-style 'fg=colour23 bg=colour2 bold'
setw -g window-status-current-format ' [#I] #[fg=colour8]:#[fg=colour255]#W#[fg=colour249]#F '

# Another window which is in backgroud
setw -g window-status-style 'fg=colour233 bg=colour8'
setw -g window-status-format ' [#I] #[fg=colour250]:#[fg=colour250]#W#[fg=colour244]#F '

# messages
set -g message-style 'fg=colour233 bg=colour8 bold'

# don't rename windows automatically
set-option -g allow-rename off

Permalink at https://www.physicslog.com/cs-notes/tmux

Published on May 28, 2021

Last revised on Jul 2, 2023

References