Skip to content

Instantly share code, notes, and snippets.

@bahmutov
Last active Mar 31, 2017
Embed
What would you like to do?
tmux basics

install

Install on Mac using brew install tmux and start with tmux

main commands

See help (list of commands) with Control-b ? key combination. Leave help view by pressing q key. From now on use Control-b (aka C-b) to start all tmux commands (C-b is called command prefix and can be changed, see tmux.config options).

Panes

Split into vertical panes C-b % and navigate left - right using C-b LEFT and C-b RIGHT. Split pane horizontally using C-b ". To close a pane either type command exit or C-d.

Windows (collections of panes)

To start new tmux window use C-b c (c stands for create). Then you can navigate back and forth using C-b n and C-b p (as in next and previous).

Sessions

Detach from a session, but leave it running in the background C-b d (lowercase d stands for detach). See list of tmux sessions from "normal" terminal tmux ls. Then attach to specific name of the session (first column) using tmux attach -t <name>. To rename the current session use C-b $.

  • To see and switch to another session from inside tmux use C-b s (lower case s stands for session) or by pressing C-b ( and C-b )
  • Rename a session from outside tmux using tmux rename-session -t <name> <new name>
  • Create a new session from terminal right tmux new -t <name>
  • Kill session from a terminal tmux kill-session -t <name>

Cool thing about tmux sessions - they stay even if you accidentally close the terminal application.

Pane zoom

Zoom in / out for a ssingle pane using C-b z

tmux.config

You can change tmux options by creating ~/.tmux.conf file. For example to use C-a as a prefix instead of C-b you can enter the following:

# set C-a as the prefix combination
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Exit all tmux sessions and start again for changes to take effect. Or reload the config file from the tmux itself using prefix : then typing source ~/.tmux.conf and "enter". You can even bind a key to quickly source the config file by having in the file itself

# easy reloading
bind R source-file ~/.tmux.conf

Scroll

You cannot scroll through the previous output in a pane using mouse. You need to switch to copy mode using prefix [ and then use up and down arrows. Use q to quit the copy mode.

Mouse mode

You can enable mouse mode to allow switching panes, resizing them and even scrolling using mouse by typing prefix : and then set mouse on. A good idea is to enable keys to quickly switch mouse mode on and off in your ~/.tmux.conf file

# mouse mode keys
bind m set -g mouse on
bind M set -g mouse off

extra info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment