Skip to content

Instantly share code, notes, and snippets.

@alexolinux
Last active December 4, 2024 13:06
Show Gist options
  • Save alexolinux/26cb1e453be9348ef7bd88689bf53160 to your computer and use it in GitHub Desktop.
Save alexolinux/26cb1e453be9348ef7bd88689bf53160 to your computer and use it in GitHub Desktop.
TMUX: Transform Your Terminal into a Productivity Powerhouse

TMUX: Elevate Your Terminal Experience


Session Management:

  • Start TMUX Session: tmux new
  • Start TMUX Named session: tmux new -s <NAME>
  • Start TMUX Named detached session: tmux new -s <NAME> -d
  • Kill session: tmux kill-session -t <NAME>
  • Kill ALL sessions: tmux kill-server
  • List sessions: tmux ls
    • Attach to a session: tmux a -t <session-name>
    • Detach from the session: Ctrl + b, d
    • Create a new session: Ctrl + b, c
    • Rename Session: Ctrl + b, $
    • Switch to the next session: Ctrl + b, (
    • Switch to the previous session: Ctrl + b, )
    • Interactive list/select sessions: Ctrl + b, w

Window Management:

  • Create a new window: Ctrl + b, c
  • Switch to the next window: Ctrl + b, n
  • Switch to the previous window: Ctrl + b, p
  • Rename the current window: Ctrl + b, ,
  • Close the current window: Ctrl + b, &
  • Fullscreen IN/OUT current windows: Ctrl + b, z
  • Interactive list/select windows: Ctrl + b, w

Pane Management:

  • Split pane horizontally: Ctrl + b, %
  • Split pane vertically: Ctrl + b, "
  • Switch to the next pane: Ctrl + b, o
  • Resize pane: Ctrl + b, arrow keys
  • Close the current pane: Ctrl + b, x

Miscellaneous:

  • Command prompt: Ctrl + b, :
  • Show help: Ctrl + b, ?
  • Reload configuration: Ctrl + b, r

More Productivity:

  • ON/OFF Broadcast input to all panes: Ctrl + b, : >> setw synchronize-panes <on/off> >> <ENTER>
  • ON/OFF Broadcast input to specific panes: Ctrl + b, <window> : >> setw synchronize-panes <on/off> >> <ENTER>

Additional TMUX Tricks:

Copy and Paste:

  • Enter copy mode: Ctrl + b, [
  • Start selection: Move the cursor to the start position and press Space
  • Copy selection: Press Enter to copy the selected text
  • Paste copied text: Ctrl + b, ]

Customization:

  • Change the prefix key: You can change the default prefix key (Ctrl + b) by adding the following line to your ~/.tmux.conf:

  • **My Best Ever TMUX Configuraion :) **

# Set prefix key to Ctrl-a (instead of the default Ctrl-b)
set -g prefix C-a
unbind C-b

#-- ---------------------------------------------------------------------------------------------------------------------------------------
#-- My TMUX Custom Confs --------
set-option -g set-clipboard on

# Bind Shortcuts
bind b setw synchronize-panes \; display-message  "Broadcast mode toggled"
bind v if-shell -F "#{?mouse,1,0}"                "set -g mouse off; display 'Mouse mode: OFF'" "set -g mouse on; display 'Mouse mode: ON'"

#-- TMUX Plugins Section --------------------------------------------------------
#-- Uncomment after proceeding with the Plugins Installation (Next Section below)

#-- TMUX Plugins (https://github.com/tmux-plugins/tpm) 
#set -g @plugin 'tmux-plugins/tpm'
#set -g @plugin 'tmux-plugins/tmux-sensible'
#set -g @plugin 'MaximilianGaedig/tmux-filter'     #(Usage: press prefix + F)

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
#run '~/.tmux/plugins/tpm/tpm'

#-- ---------------------------------------------------------------------------------------------------------------------------------------

#-- Color Customization Section ----------------------------------------
# Set default terminal mode
set -g default-terminal "screen-256color"

# Set the status bar
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green]#H #[fg=white]|'
set -g status-right '#[fg=yellow]%Y-%m-%d #[fg=white]|#[fg=cyan]%H:%M:%S'
#-- Color Customization Section ----------------------------------------

# Set pane splitting behavior
bind | split-window -h
bind _ split-window -v

# Enable window renaming
#set -g automatic-rename on

# Set history limit
set -g history-limit 10000

# Use vim key bindings in copy mode
setw -g mode-keys vi

# Enable window and pane navigation with Alt + arrow keys
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

# Reload tmux configuration
bind r source-file ~/.tmux.conf \; display "Config reloaded!"

# Set up a custom key binding for creating a new window
bind c new-window -n "NewMux"

# Set up a custom key binding for killing a pane
bind x kill-pane

# Set up a custom key binding for killing a window
bind X kill-window

# Set up a custom key binding for switching to the last window
bind l last-window

# Set up a custom key binding for resizing panes
bind -r < resize-pane -L 5
bind -r > resize-pane -R 5
bind -r + resize-pane -U 5
bind -r - resize-pane -D 5

How to use this configuration:

  • Split Window:
    • Vertically: Ctrl-a then |
    • Horizontally: Ctrl-a then _
  • Navigate Between Panes:
    • Use Alt + Arrow keys (e.g., Alt + Left to move left).
  • Create a New Window:
    • Press Ctrl-a then c.
  • Switch to the Last Window:
    • Press Ctrl-a then l.
  • Kill a Pane:
    • Press Ctrl-a then x.
  • Kill a Window:
    • Press Ctrl-a then X.
  • Reload conf:
    • Press Ctrl-a then r.

Plugins Section:

  • Create a TMUX Plugin Folder: mkdir ${HOME}/.tmux/plugins
  • Set XDG_CONFIG_HOME to the SHELL Environment: export XDG_CONFIG_HOME="$HOME/.config"
  • Create a Simlink: ln -s $HOME/.tmux.conf $XDG_CONFIG_HOME/.tmux.conf

Now, follow the steps using Tmux Plugin Manager

Manage Plugins

  • Once you have added the New plugin: prefix + I
  • Updating ALL TMUX plugins: prefix + U
  • Updating a specific plugin: prefix + alt + u
  • Deleting a specific plugin: prefix + alt + d (Choose by prompt list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment