tmux
panes.I had been missing the “select and middle-click” method for copying
and pasting stuff in tmux
panes.
Thanks to this post, I learned that I can use the Shift key and
bypass tmux
’s own copy and paste method.
Key/Mouse Binding | Action |
---|---|
Shift + Mouse left button double-click | Copies the double-clicked word |
Shift + Select using mouse | Copies the selection |
Shift + Mouse middle button click | Pastes the copied text using above method in the tmux pane |
Ever wondered how you would send the clear
command to each pane,
in each window, in each session in tmux
, or how you would do
source your shell config file in each after each tweak?
Here are few excerpts from my .tmux.conf
that allow doing just
that.
Thanks to the tip in comments from Bob Fleming, I learned that tmux
has a -a
switch for the list-panes
command.
From man tmux
,
list-panes [-as] [-F format] [-t target] (alias: lsp) If -a is given, target is ignored and all panes on the server are listed. If -s is given, target is a session (or the current session). If neither is given, target is a window (or the current window). For the meaning of the -F flag, see the FORMATS section.
With that knowledge, the older version of the E binding now reduces to,
# Send the same command to all panes/windows/sessions
bind E command-prompt -p "Command:" \
"run \"tmux list-panes -a -F '##{session_name}:##{window_index}.##{pane_index}' \
| xargs -I PANE tmux send-keys -t PANE '%1' Enter\""
tmux
pane: C-z E1source ~/.alias; clear
(this is entered in the tmux command
prompt).~/.alias
in all panes, and then clear the
terminals as well.##
#The #
character needs to be escaped by another #
and typed as
##
, only when used inside the run-shell
command.
.. because otherwise, tmux run-shell
command will replace the
unescaped #{session_name}
, #{window_index}
and #{pane_index}
with
their current values before executing the command.
With the hashes escaped, those variables will be evaluated at run time.
But if you were to type the above command directly in the terminal,
without the run-shell
command wrapper, you would use only single
#
:
tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index}"
The list-panes
command has another useful switch: -s
, which takes
an optional argument, a session name. If that argument is not
supplied, it takes the current session name by default.
Below C-e binding is used to send a command to all panes, in all windows, but only in the current session.
bind C-e command-prompt -p "Command:" \
"run \"tmux list-panes -s -F '##{session_name}:##{window_index}.##{pane_index}' \
| xargs -I PANE tmux send-keys -t PANE '%1' Enter\""
# Send the same command to all panes/windows/sessions
bind E command-prompt -p "Command:" \
"run \"tmux list-sessions -F '##{session_name}' \
| xargs -I SESS tmux list-windows -t SESS -F 'SESS:##{window_index}' \
| xargs -I SESS_WIN tmux list-panes -t SESS_WIN -F 'SESS_WIN.##{pane_index}' \
| xargs -I SESS_WIN_PANE tmux send-keys -t SESS_WIN_PANE '%1' Enter\""
I have set my tmux prefix to C-z. ↩︎