Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

One nice feature of screen is its ability to assign keyboard shortcuts to groups called "classes". With bind -c, you could assign that shortcuts to a particular class, and binding command -c <class> to a key allowed you to select that class. This allowed multi-tier keyboard shortcuts. For example, I used the x key to select a class dedicated common commands. By having these launcher shortcuts in their own class, it is possible to use mnemonic keys without worrying about conflicts with the normal set of key-bindings. Is there any way to replicate this feature in tmux?

Example

# from my .screenrc
bind -c execute o screen -t imap 10 offlineimap.sh -o
bind -c execute m screen -t mpd ncmpcpp
bind -c execute w screen -t vw vimwiki
# ... more application launchers 
bind x command -c execute

Usage: prefixx enters the launcher key class, where I put all my application keyboard shortcuts.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

After understanding better what you are trying to do, I think a short bash script is the best way to go (sorry, I don't think a tmux-only solution similar to screen command classes exists):

In .tmux.conf:

bind-key x command-prompt -p "launch what?" " "run-shell \"tmux-launcher %%\""

tmux-launcher should be an executable shell script somewhere in your path:

#!/bin/bash
case $1 in 
  o) tmux new-window -n imap -t 10 offlineimap.sh -o ;;
  m) tmux new-window -n mod ncmpcpp ;;
  w) tmux new-window -n vw vimwiki ;;
esac

One drawback is that you must type return after the letter that selects the window to create.

share|improve this answer
add comment

As far as I know, tmux does not support command classes like this. However, it might be possible to accomplish a task for which screen command classes are suitable in a different way in tmux.

Here's an example from the screen man page, where windows whose indices are higher than 9 may be selected:

 bind -c demo1 0 select 10
 bind -c demo1 1 select 11
 bind -c demo1 2 select 12
 bindkey "^B" command -c demo1

The command class 'demo1' lets you select window 12 using "Ctrl-a Ctrl-B 2" (or would it be just "Ctrl-B 2"? I'm rusty with screen configuration).

In tmux, you could select window 12 using "Ctrl-b w c", where "Ctrl-b w" is the default key binding to invoke the choose-window command, and 'c' is the shortcut for selecting window 12 from the interactive menu of windows.

So, my general advice is to explore the tmux command set to see if there is a tmux idiom available for what you would accomplish using command classes in screen. If you have a specific task in mind, I encourage you to post it as a separate question.

share|improve this answer
    
I described one use case in my question, which is to have a separate prefix key for application launchers, essentially giving the application launchers their own "name-"/"key-"space instead of hunting for unused, hard-to-remember keys among the default set. –  jw013 May 14 '12 at 14:41
    
Please post an excerpt from your .screenrc file; it's possible you could adapt a solution in tmux using the command-prompt command. –  chepner May 14 '12 at 14:48
    
I've edited the question. –  jw013 May 14 '12 at 14:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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