Skip to content

Instantly share code, notes, and snippets.

@sharjeelaziz
Last active November 12, 2023 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sharjeelaziz/2ce03adde5e13654ffebf54624b48f8a to your computer and use it in GitHub Desktop.
Save sharjeelaziz/2ce03adde5e13654ffebf54624b48f8a to your computer and use it in GitHub Desktop.
tmux commands refresher with config
set -g @plugin 'tmux-plugins/tmux-logging'
#set prefix
set -g prefix C-a
bind C-a send-prefix
unbind C-b
set -g history-limit 100000
set -g allow-rename off
bind-key j command-prompt -p "Join pane from:" "join-pane -s :'%%'"
bind-key s command-prompt -p "Send pane to:" "join-pane -t :'%%'"
set-window-option -g mode-keys vi
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

tmux refresher

Start tmux as a session so that in case of a disconnection you session is still active on the host.

Default prefix key is ⌃ Control + b but we have changed it to ⌃ Control + a

Sessions

Create new tmux session

tmux new -s session-name

Attach to a session

tmux ls
tmux attach -t session_name

Detach from a Session: prefix d

Rename a session: prefix ,

Copy Mode

Move to Copy Mode: prefix [

Use page up and page down to move around. Hit space to enter into copy mode, select text, hit ⏎ Enter to copy into the vim buffer.

Open vim to paste: prefix ] to paste

Synchronize Panes

prefix :setw synchronize-panes to synchronize panes and again to disable

Navigation

Send window as a pane to another window: prefix s

Join a window as a pane to current window: prefix j

Moving pane to its own window: prefix !

Change to the next layout (move through layouts): prefix space

Veritcal split: prefix %

Horizontal split: prefix "

Move around in windows: prefix

Zoom in/out to any windows: prefix z

Resize a window: prefix ^ hold ctrl in this case

Move the window to other layout: prefix {

Move the window to other layout: prefix }

Logging

Toggle (start/stop) logging in the current pane.

  • Key binding: prefix shift+p
  • File name format: tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
  • File path: $HOME (user home dir)
    • Example file: ~/tmux-my-session-0-1-20140527T165614.log

Screen Capture

Save visible text, in the current pane. Equivalent of a "textual screenshot".

  • Key binding: prefix alt+p
  • File name format: tmux-screen-capture-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
  • File path: $HOME (user home dir)
    • Example file: tmux-screen-capture-my-session-0-1-20140527T165614.log

Save complete history

Save complete pane history to a file. Convenient if you retroactively remember you need to log/save all the work.

  • Key binding: prefix alt+shift+p
  • File name format: tmux-history-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log
  • File path: $HOME (user home dir)
    • Example file: tmux-history-my-session-0-1-20140527T165614.log

NOTE: this functionality depends on the value of history-limit - the number of lines Tmux keeps in the scrollback buffer. Only what Tmux kept will also be saved, to a file.

Use set -g history-limit 110000 in .tmux.conf, with modern computers it is ok to set this option to a high number.

Clear pane history

Key binding: prefix alt+c

This is just a convenience key binding.

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