Skip to content

Instantly share code, notes, and snippets.

@krishna1306
Last active August 9, 2023 04:27
Show Gist options
  • Save krishna1306/16969ed7da6fdf1f4d3ce9fdb14b7eb3 to your computer and use it in GitHub Desktop.
Save krishna1306/16969ed7da6fdf1f4d3ce9fdb14b7eb3 to your computer and use it in GitHub Desktop.
TMUX Commands

Using TMUX on Mac - Best Way

https://www.youtube.com/watch?v=DzNmUNvnB04

Install TMUX using homebrew

brew install tmux

# Check version ('V' is capital V)
tmux -V

Get TPM - TMUX Plugin Manager

https://github.com/tmux-plugins/tpm

  1. Create a config file
touch ~/.config/tmux/tmux.conf

TMUX Basics

TMUX contains three objects

  1. Sessions
  2. Windows
  3. Panes

TMUX Commands - Windows and Panes

TMUX by defaults use ctrl + b as prefix

Function Key Combination
Create new window prefix c
Select a window prefix window-number
Cycle between windows prefix n (or) prefix p
Kill window prefix &
Vertical Panes prefix %
Horizontal Panes prefix "
Navigate panes prefix arrow-keys
Swap panes prefix { (or) prefix }
Choose a pane prefix q -> and then select a number
Zoom into a pane prefix z
Turn pane into window prefix !
Close the pane exit or prefix x

Managing TMUX Sessions

# create a tmux session
tmux

# create a tmux session with name
tmux new -s my-session

Access command mode in TMUX inside a window using -> prefix + : (much like VIM)

# create new session from inside a session
:new
# See all sessions running
tmux ls

# see all sessions - from inside a session
prefix s

# see all sessions and windows - from inside a session
prefix w

Attach to TMUX

# attach to recent session
tmux attach

# attach to specific session
tmux attact -t my-session

Reference

https://tmuxcheatsheet.com

Install VIM TMUX Navigator

https://github.com/christoomey/vim-tmux-navigator

This gives us the ability to navigate split panes using ctrl + h / j / k / l

set-option -sa terminal-overrides ",xterm*:Tc"
set -g mouse on
unbind C-b
set -g prefix C-Space
bind C-Space send-prefix
# Vim style pane selection
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Start windows and panes at 1, not 0
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on
# Use Alt-arrow keys without prefix key to switch panes
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
# Shift arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window
# Shift Alt vim keys to switch windows
bind -n M-H previous-window
bind -n M-L next-window
set -g @catppuccin_flavour 'mocha'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'dreamsofcode-io/catppuccin-tmux'
set -g @plugin 'tmux-plugins/tmux-yank'
run '~/.tmux/plugins/tpm/tpm'
# set vi-mode
set-window-option -g mode-keys vi
# keybindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
@krishna1306
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment