Skip to content

Instantly share code, notes, and snippets.

@marcelomgarcia
Last active December 26, 2021 17:50
Show Gist options
  • Save marcelomgarcia/ed9ddf592d80b90751bb6f609a34946c to your computer and use it in GitHub Desktop.
Save marcelomgarcia/ed9ddf592d80b90751bb6f609a34946c to your computer and use it in GitHub Desktop.
tmux configuration and more

Tmux

Tmux Tricks

Broadcasting typing to all panes:

# To activate:
:setw synchronize-panes on

# To deactivate:
:setw synchronize-panes off

Saving buffer to a file

# Capture the pane. Better give a name to the buffer, to save it later.
capture-pane [-aepPqCJN] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]  (alias: capturep)

# Save the buffer saved with `capture-pnae` to a file.
save-buffer [-a] [-b buffer-name] path (alias: saveb)

For example:

To capture the whole content of a pane:

capture-pane -b temp-capture-buffer -S -

Then save the buffer to a file

save-buffer -b temp-capture-buffer ~/temp_buffer.txt

And to delete the buffer after saving it

delete-buffer -b capture-buffer

Tmux Configuration

My tmux.conf file. It's very simple, but it's all I need as starting point.

# Marcelo's tmux.conf
# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf

# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# switch panes using Alt-arrow without prefix
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
# Go to last used window with C-a.
bind C-a last-window


# Enable mouse mode (tmux 2.1 and above)
#set -g mouse on

# don't rename windows automatically
set-option -g allow-rename off

# Set terminal 
# mgarcia@mordor:~$ echo $TERM
# xterm-256color
set -g default-terminal "screen-256color"

# Use 'vi'-like keybinding for the buffer.
set-window-option -g mode-keys vi

# set buffer size
set-option -g history-limit 300000

# Some useful bindings.
bind ^ command-prompt -p "joinp>" "join-pane -s %1"
bind / command-prompt -p "man>" "split-window -h -l 80 'exec man %%'"
bind S command-prompt -p "ssh>" "new-window -n %1 'ssh %1'"
bind m swapp -s 0 -t 1
bind e attach -d
set -g update-environment "DISPLAY WINDOWID SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment