Skip to content

Instantly share code, notes, and snippets.

@dcuadraq
Last active June 30, 2017 17:27
Show Gist options
  • Save dcuadraq/8af63df9ba739df487865969fedc4152 to your computer and use it in GitHub Desktop.
Save dcuadraq/8af63df9ba739df487865969fedc4152 to your computer and use it in GitHub Desktop.
tmux cheat sheet

Tmux cheat sheet

Setup

brew install tmux

~/.tmux.conf

set -g default-terminal "screen-256color"
set-window-option -g mode-keys vi

Commands

bash

tmux ls # list sessions
tmux new -s name # creates session with name
tmux new -s name -n window_name # creates session with name and names the first window
tmux a -t session-name # [a, at, attach] attaches to session
tmux kill-session -t myname
# bash function by alexesba
# either creates a session with the name of the current folder or attaches to it if already exists
function tmux_start {
  TMUX_DIRNAME=${1:-$(pwd)}
  if test "`dirname $1`" = "."; then
    if test "$1" = "."; then
      TMUX_DIRNAME=$(pwd)
    else
      TMUX_DIRNAME=$(pwd)/$1
    fi
  fi

  TMUX_APP=$(basename $TMUX_DIRNAME)
  tmux has-session -t $TMUX_APP 2>/dev/null
  if [ "$?" -eq 1 ] ; then
    echo "No Session found.  Creating and configuring."
    pushd $TMUX_DIRNAME
    tmux new-session -d -s $TMUX_APP
    popd
  else
    echo "Session found.  Connecting."
  fi
  tmux attach-session -t $TMUX_APP
}

Prefix commands

Prefix then desired character. ^b is the default.
Prefix ? list all keybindings

Sessions

$ # renames session
L # switches to last session

Windows

, # renames window
c # creates window
n # moves to next window
w # window list
f # search window with a string
p # moves to previous window
& # close current window

Panes

% # splits current pane vertically
" # splits current pane horizontally
o # moves to next pane
q # shows pane's index
[arrow] # moves to pane in that direction
x # close pane
[spacebar] # cycle through pane layouts

Command mode

Enter command mode with Prefix :

:new # session
:new-window -n console
:new-window -n processes "top" # creates new window named processes and runs top
:source-file ~/.tmux.conf # reload config file
:list-buffers # shows current buffers
:choose-buffer # select buffer from the buffer list

Copy mode

This config on ~/.tmux.conf makes copy mode to feel like vi
set-window-option -g mode-keys vi

[ # enter copy mode
[spacebar] # start selecting text, [enter] to copy
[shift] v # selects by line
[enter] # exits copy mode
: # copies the whole pane
] # paste from tmux buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment