Mastering Tmux- Essential Shortcuts and Configuration Explained
If you’re a terminal power user, tmux is likely an indispensable tool in your arsenal. This terminal multiplexer allows you to manage multiple terminal sessions, split your screen into panes, and much more. Today, we’re diving deep into tmux shortcuts and configuration to help you boost your productivity.
Essential Tmux Shortcuts Explained
First, let’s cover some of the most crucial tmux shortcuts. Remember, the default prefix key is Ctrl+b, which you need to press before most of these commands:
Session Management
tmux new -s [session-name]
: Creates a new tmux session with a custom name. This is useful for organizing different projects or tasks.tmux ls
: Lists all active tmux sessions. Great for keeping track of your open sessions.tmux attach -t [session-name]
: Attaches to a specific existing session. Use this to return to a previous workspace.tmux kill-session -t [session-name]
: Terminates a specific session. Use cautiously to close an entire workspace.
Window Management
Prefix c
: Creates a new window within the current session. Think of this as creating a new tab in a browser.Prefix ,
: Allows you to rename the current window. Useful for organizing and identifying your windows.Prefix n
: Moves to the next window in the session. Quick way to cycle through your windows.Prefix p
: Moves to the previous window in the session. Allows backwards navigation through windows.Prefix [0-9]
: Switches directly to the window with the specified number. Fast way to jump to a specific window.
Pane Management
Prefix %
: Splits the current pane vertically. Creates a new pane to the right of the current one.Prefix "
: Splits the current pane horizontally. Creates a new pane below the current one.Prefix arrow key
: Navigates between panes in the direction of the arrow key. Allows easy movement between panes.Prefix z
: Toggles zoom on the current pane, making it full-screen. Great for focusing on one task temporarily.
Copy Mode
Prefix [
: Enters copy mode, allowing you to navigate the terminal history and select text.Space
(in copy mode): Starts text selection. Use this to begin highlighting text you want to copy.Enter
(in copy mode): Copies the selected text to tmux clipboard.Prefix ]
: Pastes the text from tmux clipboard. Quick way to insert previously copied text.
Miscellaneous
Prefix d
: Detaches from the current session. Useful when you want to leave a session running in the background.Prefix ?
: Displays a list of all tmux shortcuts. Handy reference when you forget a shortcut.Prefix :
: Enters command mode, allowing you to type tmux commands directly.Prefix t
: Shows a big clock in the current pane. Useful when you need to check the time quickly.
Customizing Your Tmux Configuration
Now, let’s explore how to customize your tmux experience with a powerful configuration file. Here’s a sample configuration with explanations:
set -g mouse on
unbind C-b set-option -g prefix C-a bind-key C-a send-prefix
bind | split-window -h bind - split-window -v unbind ’”’ unbind %
bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D
set-option -g allow-rename off
This configuration does several things:
- Enables mouse support for easier navigation and resizing.
- Changes the prefix key from Ctrl+b to Ctrl+a for easier reach.
- Remaps pane splitting to more intuitive | and - keys.
- Allows pane switching with Alt+Arrow keys without using the prefix.
- Prevents automatic window renaming for better organization.
Styling Your Tmux
You can also customize the appearance of tmux. Here’s a snippet from our configuration that sets a custom color scheme:
set -g pane-border-style ‘fg=red’ set -g pane-active-border-style ‘fg=yellow’
set -g status-position bottom set -g status-style ‘fg=red’ set -g status-right ‘%Y-%m-%d %H:%M ’ setw -g window-status-current-style ‘fg=black bg=red’ setw -g window-status-style ‘fg=red bg=black’
This configuration creates a sleek red and yellow theme, with a status bar at the bottom showing the date and time.
Conclusion
Mastering these tmux shortcuts and configuring it to your liking can significantly boost your terminal productivity. Each shortcut is designed to make your workflow smoother and more efficient. Experiment with these settings, practice the shortcuts, and don’t be afraid to further customize your tmux to fit your workflow perfectly. Happy terminal multiplexing!
This is my prespective, not the official one. Refer official documents for more informationMIT © Sujal Choudhari.