There is probably a simpler method, but this works. Put in your ~/.tmux.conf
, eg
bind-key m run-shell 'v=#D; tmux send-keys ${v#%}'
Then typing C-b m
should insert the pane number. #D
is replaced by %0
for pane 0 and so on. ${v#%}
is to remove the %
part, assuming the bash shell. To bind to a key without needing the C-b
, eg to C-o
, use bind-key -n C-o ...
.
To have a different number in each pane when synchronised, you will have to temporarily switch sync off, send a char to each pane, and restore sync.
Here's a bash script, say mytmux
you can put in your PATH and call from your ~/.tmuxrc
.
#!/bin/bash
# tmux helper. http://unix.stackexchange.com/a/325816/119298
if [[ $(tmux show-window-option synchronize-panes) == *on ]]
then tmux set-window-option -q synchronize-panes off
restore="tmux set-window-option -q synchronize-panes on"
fi
tmux list-panes -F '#{window_index} #{pane_index}' |
while read winid pane
do tmux send-keys -t $winid.$pane $pane
done
$restore
You can then set up a binding for C-b n
in your configuration:
bind-key n run-shell "mytmux"