Difference between revisions of "Tmux"

From ArchWiki
Jump to: navigation, search
(troubleshooting section with reading ~/.tmux.conf issue)
(Split window and remain current directory: clarify WHY the split trick doesn't work while using a text editor)
Line 119: Line 119:
   bind v send-keys " ~/mbin/split-tmux -h" \; send-keys "Enter"
   bind v send-keys " ~/mbin/split-tmux -h" \; send-keys "Enter"
   bind n send-keys " ~/mbin/split-tmux -v" \; send-keys "Enter"
   bind n send-keys " ~/mbin/split-tmux -v" \; send-keys "Enter"
(However, this trick doesn't work when you are using vim.)
Since this trick simply injects a keys into your session it only works if you're at a command prompt (i.e. it doesn't work while you are using vim, emacs, etc.)
==ICCCM Selection Integration==
==ICCCM Selection Integration==

Revision as of 16:21, 5 October 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tmux is a "terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached." [1]

Tmux is notable as a BSD-licensed alternative to GNU Screen. Although similar, there are many differences between the programs, as noted on the tmux FAQ page. Most notably, tmux is currently under active development, in contrast to screen, which hasn't had a stable release since August 8, 2008.


A stable version of tmux may be installed using pacman:

# pacman -S tmux

Alternatively, tmux-git is available from the AUR.


A user-specific configuration file should be located at Template:Filename, while a global configuration file should be located at Template:Filename. Default configuration files can be found in Template:Codeline.

Key bindings

Prefix all commands with Template:Codeline
Cmd Action
c Create a new window
n Change to next window
p Change to previous window
" Split pane horizontally
% Split pane vertically
, Rename current window
o Move to next pane

By default, command key bindings are prefixed by Ctrl-b. For example, to vertically split a window type Template:Codeline.

After splitting a window into multiple panes, you can resize a pane by the hitting prefix key (i.e. Template:Codeline) and, while continuing to hold Ctrl, press Left/Right/Up/Down. Swapping panes is achieved in the same manner, but by hitting o instead of a directional key.

Tip: To mimic screen key bindings copy Template:Filename to either of the configuration locations.

Key bindings may be changed with the bind and unbind commands in Template:Filename. For example, you can change the prefix key (i.e. Template:Codeline) to Template:Codeline by adding the following commands in your configuration file:

unbind C-b
set -g prefix C-a

Additional ways to move between windows include:

Ctrl-b l (Move to the previously selected window)
Ctrl-b w (List all windows / window numbers)
Ctrl-b <window number> (Move to the specified window number, the default bindings are from 0 – 9)
Ctrl-b q  (Show pane numbers, when the numbers show up type the key to goto that pane)

What if you have 10+ windows open? Tmux has a find-window option & keybinding.

Ctrl-b f <window name> (Search for window name)
Ctrl-b w (Select from interactive list of windows)

Browsing URL's

To browse URL's inside tmux you must have urlview installed and configured:

bind-key u capture-pane \; save-buffer /tmp/tmux-buffer \; run-shell "$TERMINAL -e 'cat /tmp/tmux-buffer | urlview'"

Setting the correct term

If you are using a 256 colour terminal, you will need to set the correct term in tmux. You can do this in either the Template:Filename:

set -g default-terminal "screen-256color" 

or in your Template:Filename with a test like:

# for tmux: export 256color
[ -n "$TMUX" ] && export TERM=screen-256color

Session initialization

You can have tmux open a session with preloaded windows by including those details in your .tmux.conf

new  -n WindowName Command
neww -n WindowName Command
neww -n WindowName Command

To start a session with split windows (multiple panes), include the splitw command below the neww you would like to split; thus:

new  -s SessionName -n WindowName Command
neww -n foo/bar foo
splitw -v -p 50 -t 0 bar
selectw -t 1 
selectp -t 0

would open 2 windows, the second of which would be named foo/bar and would be split vertically in half (50%) with foo running above bar. Focus would be in window 2 (foo/bar), top pane (foo).

Note: Numbering for sessions, windows and panes starts at zero, unless you have specified a base-index of 1 in your Template:Filename

To manage multiple sessions, source separate session files from your conf file:

# initialize sessions
bind F source-file ~/.tmux/foo
bind B source-file ~/.tmux/bar

Scrolling issues

If you have issues scrolling with Shift-PageUp/Shift-PageDown in your terminal, try this:

set -g terminal-overrides 'xterm*:smcup@:rmcup@'

Split window and remain current directory

Create a excutable file as follows, for example ~/mbin/split-tmux:

 #!/usr/bin/env bash
 tmux split-window $1
 tmux send-keys " cd $PWD;clear"
 tmux send-keys "Enter"

and change the configure from:

 bind v split-window -h
 bind n split-window -v


 bind v send-keys " ~/mbin/split-tmux -h" \; send-keys "Enter"
 bind n send-keys " ~/mbin/split-tmux -v" \; send-keys "Enter"

Since this trick simply injects a keys into your session it only works if you're at a command prompt (i.e. it doesn't work while you are using vim, emacs, etc.)

ICCCM Selection Integration

It is possible to copy a tmux paste buffer to an ICCCM selection, and vice-versa, by defining a shell command which interfaces tmux with an X11 selection interface. The following tmux config file snippet effectively integrates Template:Codeline with the current tmux paste buffer using xclip:


Tips & tricks!

To start tmux when you login to a standard terminal, simply add the following line of bash code to your .bashrc before your aliases..

 [[ $TERM != "screen" ]] && tmux && exit

Example .bashrc:

 # ~/.bashrc
 # If not running interactively, do not do anything
 [[ $- != *i* ]] && return
 [[ $TERM != "screen" ]] && tmux && exit
 # Irrelevant from here on, but does show that things here are working from within tmux..
 alias svile="sudo vile"
 alias updatedb="sudo updatedb"
 alias nopaste="curl -F 'sprunge=<-' http://sprunge.us"
 pacman() {
         case $1 in
                 -S | -S[^sih]* | -R* | -U*)
                         /usr/bin/sudo /usr/bin/pacman-color "$@" ;;
                 *)      /usr/bin/pacman-color "$@" ;;
Note: At first you may read screen as if we were using screen and not tmux, but tmux also uses screen for the TERM enviroment variable..

This snippet does the same thing, but also checks tmux is installed before trying to launch it. It also tries to reattach you to an existing tmux session at logout, so that you can shut down every tmux session quickly from the same terminal at logout.

 if which tmux 2>&1 >/dev/null; then
     # if no session is started, start a new session
     if test -z ${TMUX}; then
     # when quitting tmux, try to attach
     while test -z ${TMUX}; do
         tmux attach || break


If you are having issues with tmux not reading ~/.tmux.conf make sure that you have stopped all running tmux session because tmux only reads the configuration file when the server is first started.

See also