Search code examples
bashvimtmux

Delimiter for complex commands/bindings in tmux config


I am looking for a way to make the following line right in my tmux config:

bind -n S-F12 unbind -n S-Left \; unbind -n S-Right \; unbind -n S-Down \; unbind -n S-Up \; unbind -n M-Left \; unbind -n M-Right \; unbind -n M-Down \; unbind -n M-Up \; bind -n S-F12 source "$HOME/.tmux.conf"  \; display-message "Tmux Vim Mode: DISABLED" \; display-message "Tmux Vim Mode: Enabled"

The point is to toggle some bindings when doing S-F12 and printing a message on success. The thing is that the message "Tmux Vim Mode: DISABLED" is never printed probably due to the ambiguity of the delimiters of the bindings.

Is there a way to make it work ?

ps: I don't want to create another tmux config file and use source.


Solution

  • What you might try is

    bind -n S-F12 unbind -n S-Left \; \
     unbind -n S-Right \; \
     unbind -n S-Down \; \
     unbind -n S-Up \; \
     unbind -n M-Left \; \
     unbind -n M-Right \; \
     unbind -n M-Down \; \
     unbind -n M-Up \; \
     bind -n S-F12 run-shell 'tmux source "$HOME/.tmux.conf"  \; \
                              display-message "Tmux Vim Mode: Enabled"'  \; \
     display-message "Tmux Vim Mode: DISABLED"
    

    Make sure \ is the last character on the line when you use this sort of continuation. Typing Shift-F12 will do the unbinds, and rebind to a run-shell that can cope with doing the source and display-message as a single string inside ''. I've inverted the messages to what I think you wanted, but I might be wrong.