Skip to content

Recipes

Dane Jensen edited this page May 5, 2026 · 15 revisions

Configuration file recipes

This file lists some useful configuration file snippets to control tmux behaviour.

Create new panes in the same working directory

This changes the default key bindings to add the -c flag to specify the working directory:

bind '"' split-window -c "#{pane_current_path}"
bind % split-window -hc "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

Prevent pane movement wrapping

Requires tmux 2.6 or later.

This stops the pane movement keys wrapping around at the top, bottom, left and right.

bind -r Up if -F '#{pane_at_top}' '' 'selectp -U'
bind -r Down if -F '#{pane_at_bottom}' '' 'selectp -D'
bind -r Left if -F '#{pane_at_left}' '' 'selectp -L'
bind -r Right if -F '#{pane_at_right}' '' 'selectp -R'

Send Up and Down keys for the mouse wheel

Some terminals do this by default when an application has not enabled the mouse itself. This does the same in tmux (the mouse option must also be on):

bind -n WheelUpPane if -Ft= "#{mouse_any_flag}" "send -M" "send Up"
bind -n WheelDownPane if -Ft= "#{mouse_any_flag}" "send -M" "send Down"

An alternative is to only send the keys when in the alternate screen:

bind -n WheelUpPane {
	if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' {
		send -M
	} {
		if -F '#{alternate_on}' { send-keys -N 3 Up } { copy-mode -e }
	}
}
bind -n WheelDownPane {
	if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' {
		send -M
	} {
		if -F '#{alternate_on}' { send-keys -N 3 Down }
	}
}

Make C-b w binding only show the one session

This makes the C-b w tree mode binding only show windows in the attached session.

bind w run 'tmux choose-tree -Nwf"##{==:##{session_name},#{session_name}}"'

Create a new pane to copy

Requires tmux 3.2 or later.

This opens a new pane with the history of the active pane - useful to copy multiple items from the history to the shell prompt.

bind C {
	splitw -f -l30% ''
	set-hook -p pane-mode-changed 'if -F "#{!=:#{pane_mode},copy-mode}" "kill-pane"'
	copy-mode -s'{last}'
}

C-DoubleClick to open emacs(1)

Requires tmux 3.2 or later.

C-DoubleClick on a word to open emacs(1) in a popup (handles file:line).

set -g word-separators ""
bind -n C-DoubleClick1Pane if -F '#{m/r:^[^:]*:[0-9]+:,#{mouse_word}}' {
	run -C 'popup -w90% -h90% -E -d "#{pane_current_path}" "
		x=\$(echo "#{mouse_word}"|awk -F: \"{print \\\"+\\\"\\$2,\\$1}\")
		emacs "\$x"
	"'
} {
	run -C 'popup -w90% -h90% -E -d "#{pane_current_path}" "
		emacs "#{mouse_word}"
	"'
}

Change shortcut keys in tree mode

This assigns the shortcut keys by the window index for the current session rather than by line number and uses a to z for higher numbers rather than M-a to M-z. Note that this replaces the existing uses for the a to z keys.

bind w run -C { choose-tree -ZwK "##{?##{!=:#{session_name},##{session_name}},,##{?window_format,##{?##{e|<:##{window_index},10},##{window_index},##{?##{e|<:##{window_index},36},##{a:##{e|+:##{e|-:##{window_index},10},97}},}},}}" }

Create a menu button on pane-border-status

Requires tmux 3.7 or later, see 'MOUSE SUPPORT' in tmux(1) for more details.

The ControlN (N is 0 - 9) ranges allow for arbitrary commands to be given to a mouse event on the specified range. This can be used to create customizable buttons. First, create the range inside a format. Here is an example using pane-border-format that only appears when the mouse is enabled:

set -g pane-border-status top
set -g pane-border-format "\
#{?pane_active,#[reverse],}#{pane_index}#[default] \"#{pane_title}\" \
#{?#{mouse},#[align=right] #[range=control|9][Menu]#[norange],}"

Then assign the desired behavior to the mouse event via a key binding. Here, it is bound to a menu:

bind -n MouseDown1Control9 "\
display-menu -t= -xM -yM -O -T 'Pane: #{pane_index}' \
	'#{?pane_marked,Unmark,Mark}' 'm' { select-pane -m } \
	'#{?window_zoomed_flag,Unzoom,Zoom}' 'z' { resize-pane -Z } \
	'Horizontal Split' 'h' { split-window -h } \
	'Vertical Split' 'v' { split-window -v } \
	'' \
	'Kill' 'X' { kill-pane -t= }"

Similarly, control ranges can be set in the status line formats. Here is an example implementing a kill-window button on non-current windows when they are inactive for a period of time:

set -g status on
set -g window-status-format "#{?#{>:#{e|-:#{session_activity},#{window_activity}},5},#[range=control|8][X]#[norange],}#I:#W#{?window_flags,#{window_flags}, }"
bind -n MouseDown1Control8 "kill-window -t="

Clone this wiki locally