The way we use tmux is to ssh into a main server, we will then open tmux, and create a new window for each server we ssh into (C-S, prompts for a server and this will then create a new windows and ssh into the server). What I would like to do is bind C-\ and C-"-" to split the current window and ssh into that same server instead of it opening a window for the main server. Our Home directories are mounted so my .tmux.conf and scripts all follow me to every server.

each window has the server name set, though in the future we may try to get it to servername,task (example"srv001,htop") depends on how this works out :)

The closest way we have found is nesting and using a plugin to change which server tmux would respond to the prefix. The nested windows would then split and show another pane on that server. At that point I'd probably just do another C-S(get prompted for ssh servername) and join the window(which saying that isn't a bad idea as an alternative)

Thank you for any any direction, comments, questions.

2 Answers 2


This tmux plugin makes this very easy. You can use the same keybindings as you usually use to split panes and it will automatically ssh into the host again if you are splitting from a remote and it won't if you aren't.



So you ssh into server1 and run tmux, then ssh into server2 from inside tmux. Then you want to bind a key to split the window and also ssh into server2? Is that correct?

Assuming this is right, this is the relatively common question of getting tmux to do something based on the existing state of the current window, and the answer is you need to tell it the state before your create the window, or from inside the window.

Because you already have shortcuts to create the window you could store the server name in your C-s binding and then use it in your new C-\ binding.

For example, change your C-s binding to set a user variable on the window with the target host, something like this - note this is doing the set-option from inside the new window, but before it runs ssh:

bind C-s command-prompt -pserver 'neww "tmux set -w @myserver \"%1\"; ssh \"%1\""'

Then you can use it in your C-\ binding (run-shell expands formats):

bind 'C-\' run 'tmux splitw "ssh \"#{@myserver}\""'

You could do similar with the window name if it is already the host:

bind 'C-\' run 'tmux splitw "ssh \"#{window_name}\""'

But that won't work if you change the format of the window name, or if you rename the window manually.

(If you saw my previous answer, I initially thought you can use the environment but of course that is per session not per window, it has to be a user variable.)

You must log in to answer this question.

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