The prefix key is C-b (Ctrl+b). Here we’ll use arrow to represent any of the arrow keys (left,right,up,down)
Shortcuts
Panes
" - Splits plane vertically
% - Splits plane horizontally
arrow - Navigate between panes
Ctrl+arrow - Resize current pane
q - Show the pane numbers
Windows
c - Create new window
, - Rename window
p - Move to previous window
n - Move to next window
Sessions
( - Move to previous session
) - Move to next session
d - Detach from session
b - Rename session
Scripting
If you wish to create multiple panes and launch different things from the command line, you can create a script.
In order to initiate a new session and detach from it from the session
tmux new-session -d
Then you can split the window into two panes with tmux split-window. Here, you can split the window either vertically with the -v flag, or horizontally, with the -h flag. If none are specified, then -v is assumed.
tmux split-window -v
Next you can send commands to the new pane with tmux send. Here, simply send a string followed by ENTER to send the command
tmux send 'ls' ENTER
If you wish to switch panes, you first need to determine the number. Commonly, using Ctrl+b +q will quickly show you the pane numbers. Then by using tmux select-pane, you can choose the pane to move to.
tmux select-pane -t 0
Finally, if you wish to view the session, you can use tmux attach-session. A full working example is shown below:
# launch.sh
tmux new-session -d
tmux split-window -v
tmux send 'conda activate myenv' ENTER
tmux send 'python' ENTER
tmux send 'x=1' ENTER
tmux send 'print(x)' ENTER
tmux split-window -v
tmux selected-pane -t 0
tmux send 'node' ENTER
tmux attach-session