Write the configuration file
~/.tmux.conf sets mouse on, and a fresh server starts with it on, unsourced.
~/.tmux.conf is a list of tmux commands, one per line, run when the server starts. # starts a comment.
- the file
- runs once, at server start
source ~/.tmux.confatC-b :- runs it against the server already running, so you can test without restarting
That distinction is the whole lesson. Starting a new session inside a running server does not re-read the file. And anything you set by hand disappears when the server exits, while anything in the file comes back every single start.
Run echo '# turn on mouse support' >> ~/.tmux.conf, then echo 'set -g mouse on' >> ~/.tmux.conf.
Two lines now sit in the file. >> appends; > would overwrite it.
Press C-b :, type source ~/.tmux.conf, Enter.
tmux show -g mouse now prints mouse on.
Press C-b :, type kill-server, Enter.
You drop to the plain shell, and the hand-set option goes with the server.
Run tmux new -s learn.
The new server read the file first: tmux show -g mouse prints mouse on with no sourcing.
How the configuration file is parsed
It is not a shell script. ~ and quotes work; $() does not.
Here is what just happened.
source-file executed each line as if typed at the prompt. kill-server took the old server, and tmux new started a new one, which ran the file before creating learn. A second session in a running server never triggers the file; only a fresh server does.
- Build the file one command per line; # starts a comment:echo 'set -g mouse on' >> ~/.tmux.conf
- Run the commands in a file on the running server:source ~/.tmux.conf
Go further
- A typo makes the new server print an error naming the line; fix it and
sourceagain. source-fileloads any file, so per-machine settings can live in separate files.open ~/.tmux.confedits the file in an editor over the terminal; save with Ctrl-S.
- 1
>>appends;>overwrites the file. If a line went missing,cat ~/.tmux.confand check. - 2A line starting with
#is a comment. Add one, thenset -g mouse onon its own line. - 3Load it into the running server with
C-b :thensource ~/.tmux.conf. To see it load by itself,:kill-serverthentmux new -s learn.
This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.
A real terminal, in this tab
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- ~/.tmux.conf contains the set -g mouse on line— not done yet
- The running server has mouse set to on after sourcing the file— not done yet
- The old server no longer answers— not done yet
- A different server is running and it read the configuration file at start— not done yet