8

Is it possible to configure tmux so that when you want to switch to a window that doesn't exist, it creates the window and then switches (avoiding Ctrl-b c) ?

2 Answers 2

11

Add this to ~/.tmux.conf:

bind-key 0 if-shell 'tmux select-window -t :0' '' 'new-window -t :0'

This will first attempt to switch to window 0, and if that failed, create it.

Repeat for 1-9.

1
1

I made my solution based on @JigglyNaga's approach:

bind -n M-S-Right  run-shell 'current_window=$(tmux display-message -p '#I'); next_window=$(($current_window + 1)); tmux select-window -t :$next_window; if [ "$?" -ne "0" ]; then tmux new-window -t :$next_window; fi'

When you want to go to the next window, it checks if it exists, then move on. If it doesn't, create a new one and move on.

You also need to set this:

set -g renumber-windows on

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .