Set up tmux
Install it:
sudo apt install tmux
Add this to your ~/.bashrc (or ~/.zshrc if you use zsh):
if [[ -z $TMUX ]]; then
tmux
fi
This automatically starts tmux when you open a terminal.
Note: If you use powerlevel10k, set this code before the instant prompt preamble.
Tmux buffer to clipbaord
To automatically copy tmux buffer to clipboard, add this to your ~/.tmux.conf:
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"
This bind y (for vi mode) and Enter to copy the tmux buffer to clipboard. After settings this, run tmux source-file ~/.tmux.conf.
Enable vi mode
Tmux uses the Emac style by default. To change this to vi:
setw -g mode-keys vi
Enable mouse support
If you prefer mouse support, add this:
set -g mouse on
bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "xclip -selection clipboard -i"
How to use
Splitting
To split terminal vertically, press Ctrl-b, release them and then press %. For horizontal split, press " instead of %'. Make sure to release the keys before you press % or ”`.
Coomand Cheat Sheet
tmux Command Cheat Sheet
Session Management
Start tmux:
tmux
Create a new session:
tmux new -s <session-name>
List sessions:
tmux ls
Attach to a session:
tmux attach -t <session-name>
Detach from a session:
Ctrl-b d
Kill a session:
tmux kill-session -t <session-name>
Window Management
Create a new window:
Ctrl-b c
Switch between windows:
Ctrl-b <window-number>
Rename a window:
Ctrl-b ,
(then type the name) Close a window:
Ctrl-b &
Pane Management
Split horizontally:
Ctrl-b "
Split vertically:
Ctrl-b %
Switch between panes:
Ctrl-b <arrow-keys>
(or use Ctrl-b o to cycle through)
Resize pane:
Ctrl-b
then:
→ or ← (resize horizontally)
↑ or ↓ (resize vertically)
Kill a pane:
Ctrl-b x
Miscellaneous
Command prompt:
Ctrl-b :
(for advanced commands like kill-pane, rename-session, etc.)
Scroll through history:
Ctrl-b [
(use arrow keys or PgUp/PgDn to scroll, then press q to quit)
Synchronize panes:
Ctrl-b :
then type:
setw synchronize-panes on
Copy-Paste Mode
Enter copy mode:
Ctrl-b [
Start selection:
Space
Copy selection and leave the copy mode:
Enter
Paste:
Ctrl-b ]
