Skip to content

Instantly share code, notes, and snippets.

@meilinger
Last active February 15, 2024 10:01
Show Gist options
  • Save meilinger/861b310b651c5812b5b246fc9753b2ac to your computer and use it in GitHub Desktop.
Save meilinger/861b310b651c5812b5b246fc9753b2ac to your computer and use it in GitHub Desktop.
tmux 101

tmux 101 - the terminal multiplexer

Why tmux?

  • Why use a terminal multiplexer?
    • Keeps your hands on the keyboard
    • Keep multiple terminals in eyeshot
    • Detach/re-attach remote session (eg. for long-running processes)
  • Like screen, but better

Basics

  • In documentation, C-b " means hold control while pressing b, then press " (control does not need to be held when hitting the ")
  • M-x means the same key-holding pattern, but using the meta key (also known as alt)

Install

brew install tmux --HEAD

Configure

~/.tmux.conf holds your keybindings and global settings.

My current configuration

set -g prefix C-a  # Personally, I like C-a as my prefix
bind C-a send-prefix
unbind C-b
setw -g mode-keys vi  # allows for vi for scrolling through buffer + easy searching
set -g mouse on  # mouse niceties
bind -n WheelUpPane copy-mode  # go into copy mode when scrolling up
set -g history-limit 30000  # bump buffer length
set -s escape-time 50
set -g base-index 1  # start window numbering at 1 vs 0
setw -g pane-base-index 1
# Navigate panes using vi movements
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

Use

Open

tmux  # start a new tmux session
tmux a  # attach to an existing session
tmux ls  # list sessions
tmux new -s session_name  # create new named session
tmux a -t session_name  # attach to named session

In tmux - some common ops

C-a ?  # help
C-a "  # split window vertically
C-a %  # split window horizontally
C-a x  # close pane
C-a c  # create new window
C-a :  # enter command mode
C-a w  # list windows
C-a <window_number>  # switch to window #
C-a <space>  # switch between windows layouts
C-a <arrow_keys>  # move between panes
C-a d  # detach from session
C-a [  # enter copy mode/navigate scrollback buffer

Next

Tmuxinator (thx Jose!)

  • Save your complicated tmux session configurations
  • Useful for a per-project tmux session

Resources

@hackerpain
Copy link

thanks, this was useful!

@meilinger
Copy link
Author

@hackerpain, glad you found it helpful!

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