tmux docs
tmux is a tool used to manage multiple terminal sessions. the biggest benefit is that your shells can keep running in the background even if you close the terminal window. without tmux, closing the terminal usually terminates the shell session and whatever was running inside it.
this article is about how i use tmux and how you can use it in a similar fashion with my own config, which lives in the root of my dotfiles.
first lets setup tmux and the config
note: you need nerd fonts installed, otherwise some icons in the status bar will look broken.
- install tmux. on most modern linux distros this is easy from the package manager.
- copy
.tmux.confand.tmux.conf.localinto your home directory. - open a new terminal and run:
tmux
- a status bar should appear at the bottom. that means you are now inside a tmux session.
- press
Ctrl-bthen:to open tmux command mode. - run this command:
source-file ~/.tmux.conf
- after the config loads, you should see the themed status bar at the bottom.
- now tmux is ready to use.
what tmux manages
tmux mainly works with 3 things:
- sessions
- windows
- panes
panes
a pane is one terminal view. if you split your current terminal into multiple sections, each section is a pane.
windows
a window is like a workspace or tab inside tmux. each window can contain one or many panes.
sessions
a session is a collection of windows. you can keep different projects in different sessions and switch between them whenever you want.
so the structure is basically:
session -> windows -> panes
prefix key
tmux features are usually triggered through a prefix key. after pressing the prefix, tmux waits for the next key and interprets it as a tmux action instead of sending it to the shell.
in default tmux the prefix is Ctrl-b.
in my config i mostly use Ctrl-a as the working prefix, but Ctrl-b still works too.
so when i say:
prefix cprefix xprefix r
that means:
- press
Ctrl-aorCtrl-b - release
- press the next key
practice
press Ctrl-a, then press Ctrl-c.
this opens a prompt for creating a new session. type a name and press enter.
now press prefix then $.
this opens the rename-session prompt. type a new name and press enter.
that is the basic tmux interaction model.
creating and switching sessions
sessions are how i separate projects or work contexts.
use these keys:
prefix Ctrl-c: create a new sessionprefix Ctrl-f: find and switch to a sessionprefix Shift-Tab: go back to the last sessionprefix d: detach from the current session
why detach matters
detaching means the session keeps running, but you leave it. this is one of the best tmux features.
for example:
- start a server
- run a long build
- run tests
- detach
- close the terminal
- later open terminal and reattach
the work is still there.
to reattach from outside tmux:
tmux attach
if there are multiple sessions:
tmux ls
tmux attach -t session-name
windows
windows are like tabs inside one session. i usually keep one window for editor, one for server, one for logs, one for git or builds.
useful window keys
Alt-+: create a new window without using prefixprefix c: create a new windowAlt-norAlt-=: next windowAlt-borAlt--: previous windowprefix Ctrl-l: next windowprefix Ctrl-h: previous windowprefix Tab: go to last active windowprefix 0-9: jump to a numbered windowprefix ,: rename the current windowprefix &: kill the current window
good habit
rename important windows. when the status bar shows clear names, navigation becomes much easier.
panes
panes are splits inside a window. this is what makes tmux feel really powerful.
creating panes
Alt-v: split left/rightAlt-s: split top/bottomprefix -: split top/bottomprefix _: split left/right
moving between panes
Alt-Left/Right/Up/Down: move across panesAlt-h/j/k/l: move across panes with vim keysprefix h/j/k/l: move across panesprefix Arrow keys: move across panesprefix o: move to next paneprefix ;: go to last pane
resizing panes
prefix H/J/K/L: resize by 2 cellsprefix Ctrl-Arrow: resize by 1 cellprefix Alt-Arrow: resize by 5 cells
pane actions
Alt-forAlt-z: zoom/unzoom paneprefix z: zoom/unzoom paneprefix +: maximize and restore paneAlt-_: kill current paneprefix x: kill pane with confirmationprefix <orprefix {: swap pane upwardprefix >orprefix }: swap pane downwardprefix !: break pane into its own window
my usual pane workflow
for coding i often use:
- one pane for editor
- one pane for server or watcher
- one pane for shell commands
- one pane for logs
then i use Alt-h/j/k/l or prefix h/j/k/l to move around quickly.
copy mode
tmux has its own scrollback and selection mode called copy mode. in my config it uses vi-style keys.
entering copy mode
prefix Enterprefix [
important copy mode keys
v: begin selectionCtrl-v: toggle rectangular selectionV: select liney: copy selection and exitEnter: copy and exitEscape: cancelq: cancel
movement in copy mode
h/j/k/l: move cursorw/b/e: move by word0,^,$: line movementg,G: top and bottom of historyCtrl-u,Ctrl-d: half-page movement/and?: searchnandN: next and previous search match
clipboard integration
my config also copies tmux buffers into the system clipboard.
use:
prefix y: send the current tmux buffer to the system clipboard
on this machine it uses wl-copy, but the config also supports tools like xsel, xclip, pbcopy, and clip.exe depending on platform.
buffers
tmux keeps copied text in buffers.
use these keys:
prefix b: list buffersprefix p: paste from the top bufferprefix P: choose which buffer to pasteprefix =: open buffer chooser
this is useful when you copy several things and want to paste an older one later.
mouse mode
my config keeps mouse mode off by default because i mostly navigate with keyboard.
you can toggle it with:
prefix m
when mouse mode is on, you can:
- click to select panes
- use the mouse wheel to scroll
- use right click menus in some places
- resize panes with mouse drag
this is useful when quickly demoing or when you want more visual interaction.
managing the config
my config makes editing and reloading tmux easy.
edit config
prefix e: open.tmux.conf.localin your editor and reload when you exit
reload config manually
prefix r: reload the tmux config
this is useful when changing keybindings, colors, theme settings, or plugin config.
layouts
tmux can quickly reorganize panes into layouts.
useful layout keys
prefix Space: cycle layoutsprefix E: spread panes evenlyprefix Alt-1: even-horizontalprefix Alt-2: even-verticalprefix Alt-3: main-horizontalprefix Alt-4: main-verticalprefix Alt-5: tiledprefix Alt-6: main-horizontal-mirroredprefix Alt-7: main-vertical-mirrored
these are nice when splits become messy and you want tmux to quickly reorganize them.
useful views and helpers
prefix q: show pane numbersprefix w: open window treeprefix s: open session treeprefix ?: list keybindingsprefix /: describe what a key doesprefix i: show tmux info messageprefix ~: show tmux message historyprefix t: show clock mode
these helpers are very useful when learning tmux or when you forget a shortcut.
behavior from this config
some nice quality-of-life things from my setup:
- windows are numbered from
1 - panes are numbered from
1 - vi keys are used in status and copy mode
- new windows and panes keep the current working directory
- new windows can reconnect ssh sessions when possible
escape-timeis0, so tmux feels faster- history limit is larger than default
- windows auto-rename
- windows auto-renumber when one closes
- terminal title is updated automatically
- focus events and xterm keys are enabled
plugins used in this setup
this config also enables some plugins:
tmux-plugins/tmux-copycattmux-plugins/tmux-cputmux-plugins/tmux-resurrecttmux-plugins/tmux-continuumomerxx/tmux-sessionxsainnhe/tmux-fzf
these add extra functionality like search helpers, restore support, session management, and fuzzy finding.
a simple real workflow
here is one practical way i use tmux for a coding project:
- open terminal and run
tmux - create a session with
prefix Ctrl-c - create a main coding window
- split panes with
Alt-vandAlt-s - keep editor in one pane
- keep dev server in another pane
- keep test runner or logs in another pane
- make another window for git commands
- detach with
prefix dwhen done - come back later with
tmux attach
this is why tmux is so useful. your whole workspace stays alive.
important shortcuts cheat sheet
session
prefix Ctrl-c: new sessionprefix Ctrl-f: find sessionprefix d: detach
window
Alt-+: new windowAlt-n/Alt-b: next or previous windowprefix Tab: last window
pane
Alt-v: vertical splitAlt-s: horizontal splitAlt-h/j/k/l: move pane focusAlt-f: zoom paneAlt-_: kill pane
copy
prefix Enter: copy modev: selecty: copyprefix p: paste buffer
config
prefix e: edit configprefix r: reload configprefix m: toggle mouse
final notes
tmux can feel strange at first, but after a few days it becomes one of the most useful tools in terminal workflow.
the main idea is simple:
- use sessions for projects
- use windows for separate tasks
- use panes for parallel work
- use detach so your workspace keeps running
once that clicks, tmux becomes hard to live without.