tmux key binding: Window not found

0

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?

Mikhail Kupchik

Posted 2013-03-26T13:17:55.843

Reputation: 2 381

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 – 2013-03-27T04:40:08.667

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 – 2013-03-27T16:46:48.140

Answers

3

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.

Chris Johnsen

Posted 2013-03-26T13:17:55.843

Reputation: 31 786

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 – 2013-03-27T21:32:58.913