TMUX - My configurations
Table of Contents
What is TMUX?
TMUX is a short form for Terminal MUtipleXer. It allows you to switch simply divide up your terminal real estate into tiny pseudo-terminals running it own independent shells.
Features:
Terminal Sessions - When you open/run tmux, a tmux session gets created. Each pane you create in the tmux screen gets added to this session. You can leave this session and return to it later, with its state preserved and all the shells (programs) running in that tmux continuing in the background. This is useful for switching seamlessly between projects, as I have one session per project.
Using TMUX on remote machines - Since TMUX is a shell program, you can use it when SSH’d into a remote machine, allowing you to “multiplex” (open a bunch of shells) from a single SSH connection. If your SSH connection drops, you can SSH back and simply
attach
back to the session you were using before without worrying about your remote apps being stopped.Terminal app independent - As TMUX is a terminal multiplexer that runs as a shell app, you can use it in any terminal emulator and utilize its keybinds. This is especially useful if you use multiple terminal emulators for work and personal use.
Session sharing - Sharing TMUX sessions to collaborate with a colleague in real time - You can share your tmux session with a colleague like sharing the terminal emulator screen. All they have to do is SSH into your machine and connect to your session.
Configurable - You can also preconfigure sessions, windows, panes, and apps on the pane to your liking without needing to set it up every time.
Install and Using TMUX
On Ubuntu/Debian distros, run sudo apt install tmux
and confirm if prompted.
To run/start a tmux session, run tmux
.
Check this link as a guide for using tmux.
My changes and additions to TMUX config
While default keybinds work for most, I have configured them to work in tandem with my Vim configuration, making it easier to memorize. Additionally, I’ve themed them according to my liking.
You can find my tmux configuration file here .
Some keybind changes:
<CTRL-a>
- TMUX prefix<CTRL-a>c
- Clock mode<CTRL-a>|
- Horizontal split window<CTRL-a>-
- Vertical split window<CTRL-a>t
- Creates new window<ALT><Left>
- Go to Left window<ALT><Right>
- Go to Right window<CTRL><Left>
<CTRL><Right>
<CTRL><Up>
and<CTRL><Down>
- Move between panes (Check here )<CTRL-a>s
- Custom FZF based session selector<CTRL-a>S
- Inbuilt session selector- Copy mode
y
(yank) - Copy to clipboard - Copy mode mouse selection - Copy to selection clipboard
<CTRL-a>C
- reload configF12
- Toggle keybinds - For nested tmux usecase.
You can sideload config file using tmux -f <config file> ....
Custom Session Create / Select using FZF
I find the built-in session selector rather limiting in terms of functionality. Therefore, I’ve wrote my own session selector based on Fzf. It enables easy switching between TMUX sessions within a few keystrokes and can also spin up a new session if one is not found.
#!/usr/bin/env zsh
sessions=$(tmux list-session -F "#{session_name}" 2>/dev/null)
selected=$(echo $sessions | fzf --height 100% --reverse --no-multi --print-query \
--preview "tmux capture-pane -pt {}" --preview-window right,90% | tail -n1)
if [[ -n $selected ]]; then
if [ -z "$TMUX" ]; then
tmux new -As $selected
else
if ! tmux has-session -t $selected 2>/dev/null; then
tmux new -ds $selected
fi
tmux switch-client -t $selected
fi
fi
unset sessions selected
To use it, save it somewhere accessible to tmux with exec permissions and bind it to a key (with prefix) using
bind <key> display-popup -h 90% -w 90% -E '<script location>'