0

There is a number of default keybindings in tmux that create menus of various sorts. Apparently, these keybindings open-code the entire menu they are displaying:

bind-key    -T prefix       <                      display-menu -T "#[align=centre]#{window_index}:#{window_name}" -x W -y W "#{?#{>:#{session_windows},1},,-}Swap Left" l { swap-window -t :-1 } "#{?#{>:#{session_windows},1},,-}Swap Right" r { swap-window -t :+1 } "#{?pane_marked_set,,-}Swap Marked" s { swap-window } '' Kill X { kill-window } Respawn R { respawn-window -k } "#{?pane_marked,Unmark,Mark}" m { select-pane -m } Rename n { command-prompt -F -I "#W" { rename-window -t "#{window_id}" "%%" } } '' "New After" w { new-window -a } "New At End" W { new-window }

I find them very useful, but I'd like to move some of these to different keys (e.g. I'd like to move < and > to [ and ]). However, copying the entire menu definition into my config seems suboptimal because I'll never notice if it changes upstream.


Is there any way I can "move" an existing tmux keybinding onto a different key, without repeating its definition in my .tmux.conf?

1 Answer 1

0

tmux list-keys does (or at least should) produce output that can be reused inside .tmux.conf or inside whatever file you choose to source (e.g. with source-file).

The idea is to get the output from tmux list-keys -T prefix "<", pass it through sed to change < into [, finally supply this to tmux source-file - (where - will be interpreted as "read from stdin"). In a shell you do this with:

tmux list-keys -T prefix "<" | sed "1 s/</[/" | tmux source-file -

In .tmux.conf you still need a shell to set up the pipeline, so use run-shell:

run-shell 'tmux list-keys -T prefix "<" | sed "1 s/</[/" | tmux source-file -'

Note sed "1 s/</[/" changes the very first < in the first line, which is right in this case. But if the key was i, you should use like sed "1 s/ i / [ /" to avoid matching i in bind-key. Or maybe in some cases you will need to search for and replace the entire -T prefix … phrase. Also remember that some characters are special in regex. Anyway, if you manage to craft sed commands that do the changes you want, the method should work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .