24

tmux has a command mode that can be accessed via C-b : and I'm wondering if there is a way to alias commands in my .tmux.conf file like split-window to something I use more often like vsp in vim.

I know I can bind keyboard shortcuts with bind but can I alias commands as well?

5 Answers 5

16

tmux 2.4 adds the command-alias array option which does this, so for example you can do

:set -s command-alias[10] vsp='split-window -h'

And then you can use :vsp in the command-prompt just like you'd expect.

3
  • 2
    How to list all the aliases you defined so far?
    – SFbay007
    Commented May 16, 2020 at 21:22
  • @SFbay007 :list-commands would make the most sense, but user-defined aliases don't show up in that list (yet!)
    – Kevin E
    Commented Feb 22, 2022 at 17:58
  • 3
    Since it’s an option (as in set-option), it’s justtmux show-options command-alias.
    – backtick
    Commented Jul 6, 2022 at 19:39
5

This doesn't appear to be possible as of tmux 2.0.

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

alias vsp="tmux split-window -h"

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

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

2

There's a mod allowing not only alias but also create new commands in tmux: http://ershov.github.io/tmux/

For example:

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

No external shell involved, no new processes spawned.

1

You can use bind. Here is an example 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)

-1

Yep. Using bind-key in you tmux.conf. For example to split tmux windows use:

bind-key v split-window -v #C-b v to split vertically
bind-key h split-window -h #C-b h horizontal

If you don't want to use prefix (C-b) just add -n param:

bind-key -n C-right next # C - → to move to next window.
1
  • 3
    Not sure this answers the original question. I believe the original question is asking if commands executed from command-prompt can be aliased, not bind-key. The functional equivalent of alias vsp="split-window -h". So someone can do something like C-b :vsp to do a vertical split like in Vim.
    – pedrohdz
    Commented May 31, 2015 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.