Is there a way for tmux command aliases?

tmux has a command mode that can be accessed via Cb : and I'm wondering if there is a way for aliases in my .tmux.conf file, like split-window , to what I use more often, like vsp in VIM.

I know that I can bind keyboard shortcuts with bind , but can I also execute commands with an alias?

+6
source share
4 answers

This is not possible with tmux 2.0.

However, one thing you can do is send commands to the incoming tmux session from the shell. This means that you can create, for example, a bash alias that can split windows:

 alias vsp="tmux split-window -h" 

You can then start vsp from the bash prompt to split the tmux window vertically. Depending on your specific use case, this may help.

It is also worth noting that if minimizing typing is the goal, tmux commands can be shortened to their shortest unambiguous prefix: sp does the same thing as split-window .

+2
source

Yeah. Using bind-key in tmux.conf. For example, to separate tmux windows, use:

 bind-key v split-window -v #Cb v to split vertically bind-key h split-window -h #Cb h horizontal 

If you do not want to use the (Cb) prefix, simply add -n param:

 bind-key -n C-right next # C - → to move to next window. 
+1
source

There, the mod allows not only an alias, but also creates new commands in tmux: http://ershov.imtqy.com/tmux/

For instance:

 proc vsp {args} { split-window -h {*}$args } 

No outer shell was involved, no new processes were present.

0
source

You can use bind . The following is an example of an alias for turning mouse-mode on and off:

 bind m \ set -g mode-mouse on \;\ set -g mouse-resize-pane on \;\ set -g mouse-select-pane on \;\ set -g mouse-select-window on \;\ display 'Mouse mode ON' bind M \ set -g mode-mouse off \;\ set -g mouse-resize-pane off \;\ set -g mouse-select-pane off \;\ set -g mouse-select-window off \;\ display 'Mouse mode OFF' 

Now you can easily use Ctrl+B m to turn it on and Ctrl+B m to turn it off (assuming Ctrl+B is your prefix)

0
source

Source: https://habr.com/ru/post/951264/


All Articles