Tmux Commands & Key Bindings: A Quick Guide
Tmux is an incredibly powerful terminal multiplexer, but if you don’t use it often, remembering all the key bindings and commands can be challenging. This guide provides a quick but comprehensive refresher on some of the most useful, yet often overlooked, commands to improve your efficiency when working with Tmux.
Basic Must-Know Commands
Before diving into lesser-known tricks, here are some essential tmux commands that everyone should know:
- Start a new session:
tmux
- Detach from session:
Ctrl-b d
- List all sessions:
tmux ls
- Attach to a session:
tmux attach -t <session_name>
- Kill a session:
tmux kill-session -t <session_name>
Less-Known but Incredibly Useful Tmux Commands
1. Quickly Rename a Session
Instead of struggling to remember which session is which:
tmux rename-session -t old_name new_name
Or using a shortcut:
Ctrl-b $
→ Prompts to rename the session.
2. Copy & Paste in Tmux Without a Mouse
- Enter Copy Mode:
Ctrl-b [
- Start selection:
Space
- Move cursor:
Arrow keys
- Copy selection:
Enter
- Paste:
Ctrl-b ]
For better experience, install the tmux-yank plugin to enable clipboard integration.
3. Reload Config Without Restarting Tmux
If you’ve made changes to your ~/.tmux.conf
, apply them without restarting:
Ctrl-b : source-file ~/.tmux.conf
4. Search Through Pane History
Tmux keeps a history of terminal output. To search within it:
Ctrl-b [
→ Enter copy mode/
→ Start searchingn
→ Move to the next matchN
→ Move to the previous match
5. Swap Panes Without Moving Windows
Ctrl-b {
→ Move the current pane leftCtrl-b }
→ Move the current pane right
6. Resize Panes Manually
If you need a custom layout, resize panes with:
Ctrl-b Alt-ArrowKey
7. Zoom in on a Single Pane
If you want to focus on one pane temporarily:
Ctrl-b z
→ Toggle zoom in/out
8. Monitor a Pane for Output Changes
Want to be notified when a process finishes?
Ctrl-b : setw synchronize-panes on
This is useful for monitoring multiple processes at once.
9. Quickly Switch Between Last Two Panes
Instead of moving between panes manually:
Ctrl-b ;
→ Switch to last active pane.
10. Create a New Window With a Predefined Name
To avoid generic window names like “bash” or “sh”:
tmux new-window -n "Dev" bash
11. Bind a Key for Easy Pane Splitting
Make splitting windows easier by adding this to ~/.tmux.conf
:
bind \ split-window -h
bind - split-window -v
Now use:
Ctrl-b \
→ Split horizontallyCtrl-b -
→ Split vertically
12. Auto-Start a Tmux Session When Logging Into SSH
To always resume a tmux session upon SSH login, add this to ~/.bashrc
:
if [[ -z "$TMUX" ]] && [[ $SSH_TTY ]]; then
tmux attach || tmux new-session -s main
fi
13. Run Commands in Multiple Panes at Once
If you need to run the same command across all panes:
Ctrl-b : setw synchronize-panes on
- Now type in any pane, and it will be mirrored.
- To disable:
Ctrl-b : setw synchronize-panes off
14. Kill All Windows But the Current One
To keep only your current window and remove the rest:
Ctrl-b : killw -a
15. Persistent Tmux Sessions After Logout
To keep tmux sessions running even after logging out, use:
tmux detach && disown
Or, for an even more resilient setup, install the tmux-resurrect plugin to save and restore sessions automatically.
With these commands and shortcuts, you’ll be able to boost your efficiency in Tmux, even if you don’t use it frequently. Bookmark this guide for quick reference the next time you SSH into a remote host!
Comments
Post a Comment