Skip to content

Instantly share code, notes, and snippets.

@petergi
Last active January 10, 2023 23:34
Show Gist options
  • Select an option

  • Save petergi/cd02e711c623df7779ee76d25a201c37 to your computer and use it in GitHub Desktop.

Select an option

Save petergi/cd02e711c623df7779ee76d25a201c37 to your computer and use it in GitHub Desktop.

As configured in tmux.conf

set-option -g default-command "tmux-shell-wrapper"

# Make shift+arrows, ctrl+arrows etc work in Vim.
set -g xterm-keys on

# See if this fixes slow ESC issues.
# http://unix.stackexchange.com/questions/23138/esc-key-causes-a-small-delay-in-terminal-due-to-its-alt-behavior
set -s escape-time 0

# Start window and pane indices at 1.
set -g base-index 1
set -g pane-base-index 1

# Status bar styling and content.
set -g status-bg black
set -g status-fg white
set -g status-left '#S '

# Show keyboard layout in prompt, assuming some script writes it to that path;
# it's "/User/…" instead of "~" so VMs can read from their symlinked OS X host home directory.
set -g status-right '#(cat /Users/$USER/.keyboard_layout 2> /dev/null) | #22T | %H:%M %d-%b-%y'
set -g status-right-length 60
set -g status-interval 2

# Highlight the active window in the status bar.
set-window-option -g window-status-current-bg yellow
set-window-option -g window-status-current-fg black

# Don't prompt to kill panes/windows.
bind-key x kill-pane
bind-key & kill-window

# Cycle panes.
bind b select-pane -t :.+
bind C-b select-pane -t :.+

# More intuitive split-window mappings.
bind "'" split-window -h
bind - split-window -v

# Maximize pane, e.g. for copying.
bind-key z resize-pane -Z

# Switch pane and zoom
# https://twitter.com/tskogberg/status/792025881573199872
bind C-z select-pane -t :.+ \; resize-pane -Z

# Reload tmux conf.
unbind r
bind r source-file ~/.tmux.conf\; display "Reloaded conf."

# http://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future

# Use vim keybindings in copy mode
setw -g mode-keys vi

# Unbork my iTerm ctrl+1 etc mappings in tmux 2.1
# https://github.com/tmux/tmux/issues/159
set -g assume-paste-time 0

start new:

tmux

start new with session name:

tmux new -s myname

attach:

tmux a  #  (or at, or attach)

attach to named:

tmux a -t myname

list sessions:

tmux ls

kill session:

tmux kill-session -t myname

In tmux, hit the prefix ctrl+b and then:

Sessions

:new<CR>  new session
s  list sessions
$  name session

Windows (tabs)

c           new window
,           name window
w           list windows
f           find window
&           kill window
.           move window - prompted for a new number
:movew<CR>  move window to the next unused number

Panes (splits)

%  horizontal split
"  vertical split

o  swap panes
q  show pane numbers
x  kill pane
⍽  space - toggle between layouts

Window/pane surgery

:joinp -s :2<CR>  move window 2 into a new pane in the current window
:joinp -t :1<CR>  move the current pane into a new pane in window 1

Misc

d  detach
t  big clock
?  list shortcuts
:  prompt

Examples

# To start tmux:
tmux

# To detach from tmux:
Ctrl-b d

# To restore tmux session:
tmux attach

# To detach an already attached session (great if you are moving devices with different screen resolutions):
tmux attach -d 

# To display session:
tmux ls

# To rename session:
Ctrl-b $

# To switch session:
Ctrl-b s

# To start a shared session:
tmux -S /tmp/your_shared_session
chmod 777 /tmp/your_shared_session

# To help screen (Q to quit):
Ctrl-b ?

# To scroll in window:
Ctrl-b PageUp/PageDown

# To reload configuration file
Ctrl-b : source-file /path/to/file

# To create a window:
Ctrl-b c

# To go next window:
Ctrl-b n

# To destroy a window:
Ctrl-b x

# To switch between windows:
Ctrl-b [0-9]
Ctrl-b Arrows

# To split windows horizontally:
Ctrl-b %

# To split windows vertically:
Ctrl-b "

# To swap windows:
Ctrl-b :swap-window -s [0-9] -t [0-9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment