If you're using SSH with VSCode to develop on a remote server, this config will help you keep your terminal sessions around even if you are disconnected from the server.
This means you can log off and enjoy a coffee, and as long as your server is still up and running, you can connect back at any time and jump back into your terminal as you left it.
tmux
Close your terminal in VSCode by clicking the trash icon beside your terminal name or type [CTRL]+[b]
then [d]
. This detaches the session but does not kill it.
tmux list-sessions
tmux attach -t <session-number>
If your remote server is Linux, set the following in your VSCode settings.json
or .code-workspace
file to make sure that you always open a new terminal with tmux
instead of bash
, so you don't forget typing tmux
next time!
{
"terminal.integrated.defaultProfile.linux": "tmux"
}
Now, clicking the plus icon in the VSCode terminal bar will automatically start a new tmux
session for you.
If you need to attach a previous session, select the dropdown beside the plus icon in the VSCode terminal bar, and create a normal bash
terminal. Then you can run tmux list-sessions
to find the previous session you want to attach to.
These are some settings I personally use.
Add these to your ~/.tmux.conf
file:
set -g mouse on
set -g history-limit 50000
Then, reload your tmux config with:
tmux source-file ~/.tmux.conf