tmux - boosting your terminal experience
/ 4 min read
Even though I generally expect apps to have sensible defaults and thus restrain
from playing too much with their configuration, there is one setting I always
update when I open a new terminal emulator. That is which command to run when it
starts. I always pick tmux
.
Many terminal emulators support opening shells in tabs and splitting windows
into horizontal or vertical panels. This is functionality that’s entirely
redundant because that’s one of the core features of tmux
.
With tmux
I can bring that functionality with me regardless of which app I use
to access the shell with no need to learn new keyboard shortcuts when I borrow a
friend’s esoteric Windows machine to ssh
to my Linux box.
But tmux
is more than just that. It also allows me to detach from a session and
resume it later. This is a feature that I use all the time. At home I have my
workstation running all the time with a bunch of tmux
sessions open (remember,
the only setting I change).
So when I’m out and about and using my laptop, I can just ssh
back home and
type tmux
, hit Ctrl-b w
to scroll through all my tmux
windows and dig up
that old vim
session I was working in. Magic!
Three panels in a tmux window.
Installation
On Debian-based systems, installing tmux
is as simple as:
The man
page will of course provide you with everything you need to know about
tmux
, but here is the list of commands I use the most:
When not in tmux
tmux
- start a new sessiontmux ls
- list all sessionstmux a -t <session>
- attach to a running session
When in tmux
When you’re inside tmux
, you can interact with it by using the Ctrl-b
prefix
and then issue a command. Here are the ones I use the most:
Full-screen windows
Ctrl-b c
- create a new full-screen windowCtrl-b <number>
- move to window<number>
Window management in tmux
.
Splitting windows into panes
Ctrl-b %
- split the window verticallyCtrl-b "
- split the window horizontallyCtrl-b q
- show pane numbers (then hit the number to move to that pane)Ctrl-b z
- zoom pane to full-screen (hitCtrl-b z
again to zoom back)Ctrl-b x
- kill the current pane (e.g if some app is stuck)Ctrl-b Ctrl-arrow keys
- resize the paneCtrl-b !
- move the current pane into a new window
Managing panes in tmux
.
Switching between sessions
Ctrl-b s
- list sessionsCtrl-b w
- choose a session from a list (with all windows)- Use arrow keys to navigate (or
j
andk
) - Use
/
to search for a window
- Use arrow keys to navigate (or
Ctrl-b d
- detach from the current session (and leave it running)
Listing sessions + listing windows and finally jumping to ncspot
.
Finding and copying text
Ctrl-b [
- enter copy mode- Use arrow keys to navigate (or
j
andk
) - Use
Space
to start selecting text - Use
Enter
to copy the selected text
- Use arrow keys to navigate (or
Ctrl-b ]
- paste the copied text
Copying text from one pane to a vim
session running in another.
Miscellaneous
Ctrl-b t
- show the timeCtrl-b ?
- show all key bindings (saves the day!)
Configuration
Even though I started this post by saying that I don’t like to fiddle with the
settings of my apps, I have set some config options to boost my tmux
experience.
Essentially what I do is the following:
- I turn on mouse support:
- I.e. I can scroll in windows and switch windows / panes with the mouse.
- Whenever I copy text (as described above), tmux also runs it through
xsel
so that I can paste it withCtrl-v
in any graphical app (you can update this to whatever clipboard manager you use). - I turn on
vi
key bindings for scrolling, etc. - I install a few plugins through the
tpm
plugin manager:tmux-sensible
just provides some sensible defaults.dracula
is the color scheme you see in all screenshots.tmux-powerline
adds a status line at the bottom of the screen.
Here is my full ~/.tmux.conf
:
If you haven’t already, make sure to give tmux
a try!