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.

My problem is I can't make tmux key bindings to switch windows.

I'm running tmux terminal multiplexer on the FreeBSD server. tmux is started automatically for all remote logins using ~/.bash_profile:

if [ $TERM = "xterm" ]; then
   ( (tmux has-session -t remote && tmux attach-session -t remote) \
  || (tmux new-session -s remote) ) && exit 0
   echo "tmux failed to start"
fi

By default, tmux windows are switched using Ctrl+B 1, Ctrl+B 2 ...
I want to switch tmux windows using F1, F2 ...

So I added the following lines to ~/.tmux.conf:

bind-key -n F1 select-window -t :1
bind-key -n F2 select-window -t :2
bind-key -n F3 select-window -t :3
bind-key -n F4 select-window -t :4
bind-key -n F5 select-window -t :5
bind-key -n F6 select-window -t :6
bind-key -n F7 select-window -t :7
bind-key -n F8 select-window -t :8
bind-key -n F9 select-window -t :9

Now when I login and press F1, tmux says: "Window not found: :1". I've tried to change to bind-key -n F1 select-window -t remote:1, the error message is similar: "Window not found: remote:1".

Switching windows from command line works, both tmux select-window -t :1 and tmux select-window -t remote:1.

How can I make it work as a key binding?

share|improve this question
    
The bindings look correct, and the bound command is obviously being run when you press F1. What does tmux list-windows show? Do you have base-index set to a high value (so that you do not normally have a window with an index as low as 1)? –  Chris Johnsen Mar 27 '13 at 4:40
    
tmux list-windows shows 1: bash* (1 panes) [108x48] [layout ce7d,108x48,0,0,0] @0 (active). base-index is set to 1 in ~/.tmux.conf. –  Mikhail Kupchik Mar 27 '13 at 16:46

1 Answer 1

up vote 3 down vote accepted

Try checking for non-visible characters in your ~/.tmux.conf file. I am able to reproduce your symptoms when the bind-key lines end with a CR (i.e. DOS/Windows-style line endings).

If you use Vim to edit, check the fileformat with :set ff?. If it is set to dos, then you can fix the file with this command:

:set ff=unix|w

If fileformat was already set to unix, then inspect the individual lines; if there are CR characters there, they should show up as ^M.

share|improve this answer
    
Yep, I've had changed .tmux.conf in Windows and uploaded it via WinSCP Far plugin. I converted all line endings to Unix style per your recommendation, and tmux works as expected now. tmux select-window -t :1<CR> didn't work because there's no :1<CR> window, and error message about missing :1<CR> window didn't display <CR> part. So I can see true reason now, and thanks for your excellent answer. –  Mikhail Kupchik Mar 27 '13 at 21:32

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.