linux_wiki:tmux

Tmux

General Information

Tmux is a terminal multiplexer. It is basically screen with more advanced features.

Checklist

  • Distro(s): Any
  • Package: tmux

Install

Install tmux:

yum install tmux
or
apt-get install tmux

Tmux Operation

1) Open a terminal

2) Start a tmux session (default name)

tmux

Start a named tmux session

tmux new -s MySession

Detach from open session

Ctrl+b d

List tmux sessions

tmux list-sessions

Attach to session

tmux attach -t MySession

Rename existing session

Ctrl+b :rename-session MyAwesomeName

Like screen, tmux has windows.

Create a new window

Ctrl+b c

Next Window

Ctrl+b n

Previous Window

Ctrl+b p

Rename Window

Ctrl+b ,
MyWindow

An advantage that tmux has over screen, is the ability to create panes.

Split window horizontally

Ctrl+b "

Split window vertically

Ctrl+b %

Kill current pane

Ctrl+b x
OR
exit

Navigate between panes

Ctrl+b up/down/left/right (arrow keys)

Maximize current pane (other pane moves to its own window)

Ctrl+b !

Auto-resize panes to equal space horizontally

Ctrl+b ESC+2

Auto-resize panes to equal space vertically

Ctrl+b ESC+1

Enter copy mode

Ctrl+b [

While in copy mode

  • Move around: arrow keys
  • Start selection: space
  • Copy selection: enter

Paste selection

Ctrl+b ]

Help

Ctrl+b ?

List Commands

Ctrl+b :list-commands

Tmux Config File

You can customize tmux with a config file in your home directory.

The following is a running list of customizations I find useful.

~/.tmux.conf

# use the vim motion keys to move between panes
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
 
# set history scroll back size (default is 2000, also set terminal scroll back to be >= )
set-option -g history-limit 5000
 
# start window index at 1 instead of 0
set -g base-index 1
 
# Allow xterm titles in terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right
set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"
 
# Set default shell
set-option -g default-shell /bin/zsh
 
# Allow mouse click to select a pane to be active
set -g mouse-select-pane on
 
# Mouse wheel scrolling for individual panes (newer versions of tmux; ie Fedora 27)
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e; send-keys -M'"
 
# Mouse wheel scrolling for individual panes (older versions of tmux; ie CentOS 7)
set -g mode-mouse on
  • Notes:
    • When enabling mouse options in tmux, the ability to highlight text as normal for a copy/paste operation goes away. Using shift temporarily over rides tmux capture of the mouse.
    • To copy/paste (if using mouse options)
      • hold shift, select text, copy
      • hold shift, right click, paste (or middle click)

Tmux Aliases

Some useful tmux aliases from ~/.bashrc

# Tmux Aliases
alias tls='tmux list-sessions'
alias tat='tmux attach -t'
alias tns='tmux new -s'

  • linux_wiki/tmux.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)