Skip to content

Instantly share code, notes, and snippets.

@on3iro
Created June 17, 2020 09:16
Show Gist options
  • Save on3iro/555a91c0664631c2acb515580c03204a to your computer and use it in GitHub Desktop.
Save on3iro/555a91c0664631c2acb515580c03204a to your computer and use it in GitHub Desktop.

Theos Tmux Cheatsheet

ToC

Minimal config

I recommend the following minimal .tmux.conf

# Make zsh default shell
set-option -g default-shell /bin/zsh

# Make vim and tmux speak the 'same' language
set-option -gw xterm-keys on

set-option -sa terminal-overrides ',RGB:RGB'

# Shorter escape time
set -s escape-time 0

# Show working directory
set -g status-left "#{pane_current_path}"

# Increase history-limit for panes
set -g history-limit 20000

# split panes using | and -
bind | split-window -h
bind - split-window -v

# reload config file
bind r source-file ~/.tmux.conf

# switch panes using alt-hjkl without prefix
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D

# stop naming windows automatically
#set-option -g allow-rename off

# enable vi-keys
setw -g mode-keys vi

Sessions

A session is a context which can contain multiple windows with multiple panes inside each. I do personally use this to quickly switch between project contexts.

Start new session

  1. Navigate to directory you would like to open a session in
  2. run tmux

Rename session

Press ctrl + b and then $

Detach from session

Detaching does not close the session and keeps it in the background. Press ctrl + b and then d.

Attach to last used session

To attach to a detached session (if you currently aren't inside an active session), run tmux attach

Attach to specific session

To attach to a specific session, first list all available sessions via tmux ls.

Now you can simply attach by using the sessions name as target: tmux attach -t <sessionName>

Switch between sessions

If you are currently inside an active session, you can switch by pressing: ctrl + b and then s. Now simply select the session you would like to use with the arrow keys. You can also use the left and right arrow keys to unfold the session an target a specific window of the session.

Quick switch between the last two used sessions

Press ctrl + b and then L to quickly switch between your last two session. (note the uppercase!)

Close all open sessions

Detach from your current session and run the following command inside your terminal: tmux kill-server. (This fully closes all sessions!)

Windows

A window is an arrangement of panes. For example you could have a window containing a pane with an instance of vim as well as two smaller panes running a development server, your test runner or even another instance of vim (or any other editor) showing a README or something. By default a session starts with a single window containing a single pane.

Renaming the current window

For the purpose of organization it might be helpful to rename your window (e.g. to have one with your dev and one with some kind of prod setup).

To do so, press ctrl + b and then ,

Opening a new window

To open a new window, press ctrl + b and then c

Switch windows

I usually target windows directly, by using their respective number: ctrl + b and then <numberOfTheWindow>

Quickly switch between the two last opened windows

ctrl + b and then l (lowercase L)

Panes

Panes are split screens comparable to a tiling window manager. You can use these to show different terminals of various sizes inside a single window.

Split current pane horizontally

ctrl + b and then "

Split current pane veritcally

ctrl + b and then %

Resize current pane

Open the command mode by pressing: ctrl + b and then :

Now type resize-pane -D <number>. The -D flag tells tmux to shrink the current pane. You can use -U (up), -R (right) and -L (left) respectively. Of course you can map these to shortcuts inside your tmux.conf as well if you would like to.

Switch between panes

If you use the config mappings shown at the top of this file, you can easily switch, by pressing alt + h/j/k/l (vim mappings). Unfortunately I can't remember the default mappings 😅.

Make the current pane full-screen

You can full-screen your current pane by pressing ctrl + b and then z. To switch off full screen mode, simply switch to another pane or use the shortcut above again.

Copy and paste text from pane with keyboard

You can open copy mode by pressing ctrl + b and then [. Now use h/j/k/l to navigate. To select text press space and select the text with h/j/k/l. If you are done, press enter. To paste the text somewhere, press ctrl + b and then ]

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