When developing in terminal you often have to open several Tmux windows at the same time:
-
server: mongod, Meteor, Elasticsearch, etc...
-
client: mongo, elasticsearch, etc...
-
editor: template.html, template.js, router.js, server.js, etc...
In most cases, you edit in editor window, save the file, switch to server window to see the result, switch back to editor window for editing again...
Now you have the second screen, say, a Windows laptop, ssh to your Linux machine via MobaXterm or Kitty. It will be more efficient if you can put the server window on the screen of the Windows machine, and keep editing on your Linux machine screen, for saving you from so many annoying switching between the screens.
It's easy for Tmux to achieve this.
Start a new session on your Linux machine, named as you like, for now, "search".
Start a new session in the terminal of the second screen named v
("viewer for short).
If you want to see the server and editor windows at the same time,
switch to the server window and run link-window -t v
(see note 1 below for details).
Now you can switch back to the editor window,
while keep server window on the other screen.
To cancel the link between the sessions,
switch to server window and run unlink-window -t v
.
Note 1:
If you define a "command-prompt" shortcut in ~/.tmux.conf:
bind -n M-a command-prompt
,
run tmux command linkw -t v
means:
press "M-a", input lin<Tab> -t v
then press
Note 2:
link-window
shares a window between multiple sessions.
To move a window to another session,
switch to the server window and run tmux command move-window -t v
.
To move it back, run move-window -s v:shell
,
where v
is the target session name defined by tmux new -s v
.