8.2 KiB
TMUX: Organized Beginner's Guide
TMUX enhances your terminal experience by enabling multiple sessions, windows, and panes management. This guide demystifies TMUX, focusing on foundational commands, customization, and visual setups.
Getting Started with TMUX
Launching Sessions
- New Session:
tmux new -s session_namestarts a new session namedsession_name. - Attach to Session:
tmux attach -t session_nameattaches to an existing session. - List Sessions:
tmux lsshows all active sessions. - Detach:
Ctrl+a ddetaches you from the current session.
Windows and Panes
- New Window:
Ctrl+a ccreates a new window within the session. - Navigate Windows:
Ctrl+a n(next) andCtrl+a p(previous). - Rename Window:
Ctrl+a ,prompts for a new name for the current window. - Split Panes: Horizontal
Ctrl+a |, VerticalCtrl+a -. - Navigate Panes:
Ctrl+a [arrow keys]orCtrl+a [h/j/k/l]for Vi-like navigation. - Resize Panes:
Ctrl+a [Shift+Arrow keys]resizes panes. - Close Pane/Window: Exiting all panes in a window or
exitin the active pane closes it.
Visual Customization and Workflow Efficiency
Edit ~/.tmux.conf for custom settings. Below are essentials for an improved look and feel:
Prefix Key
- Prefer
Ctrl+afor easier accessibility.unbind C-b set -g prefix C-a bind C-a send-prefix
Appearance
- Status Bar: Customize its look.
set -g status-bg black set -g status-fg white set -g status-left '#[fg=green](#S) #(whoami)' set -g status-right '#[fg=yellow]#(date)' - Enable 256 Color Support: Enhances visual themes.
set -g default-terminal "screen-256color"
Mouse Support
- Allows pane and window interaction using the mouse.
set -g mouse on
Key Bindings
- Customize for efficiency, e.g., pane resizing, and navigation.
bind | split-window -h bind - split-window -v bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R
Reloading Config
- Apply changes without restarting TMUX.
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
Practical Workflow
- Initiate a Session: Start your work session.
- Organize Work: Use windows for major tasks and panes for detailed work.
- Seamless Navigation: Switch between tasks efficiently with custom bindings.
- Maintain Session Integrity: Detach and reattach as needed.
Advanced Tips
- Scrollback: Enter copy mode with
Ctrl+a [for scrolling. - Script Automation: Pre-configure sessions, windows, and panes for projects.
Refreshing .tmux.conf:
tmux source-file ~/.tmux.conf
Or within TMUX: Ctrl+a : then source-file ~/.tmux.conf.
TMUX is a versatile tool, bridging the gap between simplicity and complexity. Its true power unfolds as you customize it to match your workflow, making terminal management intuitive and efficient.
TMUX: A Complete Guide for Beginners
TMUX is a terminal multiplexer that allows you to manage multiple terminal sessions within a single window. It's invaluable for managing complex workflows, maintaining persistent sessions, and organizing workspaces. This guide covers the basics to get you started with TMUX, focusing on typical workflows and setting up visuals.
Starting with TMUX
Launching TMUX
To start a new TMUX session, simply type tmux in your terminal. To create or attach to a named session (for easier management), use:
tmux new -s my_session
Detaching and Attaching Sessions
Detach from a session with Ctrl+a d (assuming you've set Ctrl+a as the prefix, as recommended).
To list all TMUX sessions:
tmux ls
Attach to an existing session by name:
tmux attach -t my_session
Managing Windows and Panes
Windows
- Create a new window:
Ctrl+a c - Switch between windows:
Ctrl+a n(next),Ctrl+a p(previous) - Rename the current window:
Ctrl+a , - Close the current window: Exit all panes in the window.
Panes
- Split pane horizontally:
Ctrl+a |(custom binding) - Split pane vertically:
Ctrl+a -(custom binding) - Navigate between panes:
Ctrl+a [arrow key]orCtrl+a [h/j/k/l](Vi-like bindings) - Resize panes:
Ctrl+a [Shift+arrow key](custom binding for resizing) - Close a pane:
exitorCtrl+din the active pane
Customizing Visuals
Edit your ~/.tmux.conf file to customize TMUX's appearance and behavior. A simple visual setup could include:
# Set the prefix to Ctrl+a for convenience
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Improve the status bar appearance
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green]Session: #S #[fg=white]|'
set -g status-right '#[fg=yellow]#(date)'
# Enable mouse support
set -g mouse on
Reload the TMUX configuration by detaching from your session and running:
tmux source-file ~/.tmux.conf
Or, within a TMUX session, press Ctrl+a and then :, type source-file ~/.tmux.conf, and hit Enter.
Sessions, Windows, and Panes Workflow
- Start a TMUX session for a new project or task (
tmux new -s project_name). - Create windows within the session for separate parts of your task (e.g., editing, running commands).
- Split windows into panes for side-by-side work on related activities.
- Detach and reattach to your session as needed, keeping your workspace intact between logins or reboots.
Additional Tips
- Scrolling: Enter copy mode with
Ctrl+a [to scroll using arrow keys or PageUp/PageDown. Pressqto exit copy mode. - Customize key bindings: To streamline your workflow, customize key bindings in
~/.tmux.conf. - Scripting TMUX: You can script TMUX commands to automate your environment setup.
TMUX is a powerful tool that, once mastered, will significantly enhance your command-line efficiency. Experiment with different configurations and workflows to fully harness TMUX's capabilities.
# Set UTF-8 support for TMUX, enhancing compatibility with wide character sets.
set -g utf8
# Set terminal to use 256 colors, enabling richer color schemes.
set -g default-terminal "screen-256color"
# Change the prefix from 'Ctrl+b' to 'Ctrl+a' for easier reach.
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Vi-like keys for pane selection. Allows moving between panes using 'h', 'j', 'k', 'l'.
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Resize panes using Shift+Arrow keys. Adjusts pane size in small steps for precise layout control.
bind -n S-Left resize-pane -L 2
bind -n S-Right resize-pane -R 2
bind -n S-Up resize-pane -U 2
bind -n S-Down resize-pane -D 2
# Reload TMUX config without restarting TMUX using Prefix+r.
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
# Split panes using '|' for vertical and '-' for horizontal splits. More intuitive symbols.
bind | split-window -h
bind - split-window -v
# Use Vim keys in copy mode to navigate text. Ensures consistency for Vim users.
setw -g mode-keys vi
# Configure the status bar's appearance and information displayed.
set -g status-interval 60 # Update interval.
set -g status-justify centre # Center-align window list.
set -g status-left-length 20 # Length of left segment.
set -g status-right-length 150 # Length of right segment.
set -g status-left '#[fg=green](#S) #(whoami)' # Show session number and user name on left.
set -g status-right '#[fg=yellow]#(uptime | cut -d "," -f 2-4)' # Show system uptime on right.
# Simplify window list appearance in the status bar.
set -g window-status-format "#I #W" # Default window format.
set -g window-status-current-format "#[bold]#I #W" # Highlight active window.
# Enable mouse support for interacting with panes, windows, and the status line.
set -g mouse on
# Set a generous history limit, allowing more scroll-back.
set -g history-limit 10000
# Ensure window indexing is continuous by renumbering after a window is closed.
set -g renumber-windows on
# Monitor for activity in windows, highlighting any changes.
setw -g monitor-activity on
set -g visual-activity on