This module discusses some features of tmux.
Tmux is a tool that can create sessions, windows and panes within one terminal. Windows can be thought of as tabs and panes can be thought of as running two terminals side by side. Or to use a house as the analogy, a house (session) has many windows, some fancy windows have panes inside. Within a sesion you can have many things going on but the advantage is if run on a remote machine you can disconnect the ssh connection, go away, reconnect later and resume where you left off! Great for remote work or running calculations that require a persistent shell.
Tmux emulating an IDE with nvim, pydoc and ipython in one window
tmuxis newer compared to GNU screen (screen), which is an older program of similar capability. Your remote computer may usescreeninstead. As alwaysman tmuxorman screenfor more help and options.
Once running in tmux commands are preceeded by a prefix (C-b) which is CTRL-b. Settings can be added and changed in the configuration file ~/.tmux.conf.
screenuses the prefixC-aand may have some overlapping commands. The default prefix can be changed intmuxif desired but be warned this may conflict with other programsC-ahas some conflicts I believe.
Below are some basic commands to get you going. You need to type the prefix then type the command, e.g. to create a new window type C-b c
Default Prefix: C-b
| Command | Description |
|---|---|
c |
create new window |
d |
detach from tmux |
n |
switch to next window |
p |
switch to previous window |
[0-9] |
switch to window [0-9] |
% |
split window/pane into horizontal panes |
" |
split window/pane into vertical panes |
| — | — |
o |
move to next pane |
q |
show pane numbers |
q[0-9] |
go to pane number |
w |
list windows and panes, select with ENTER |
SPACE |
change pane layout |
| — | — |
x |
kill current window |
& |
kill current pane |
When you detach from a tmux session
C-b dyou can reattach using the command line commandtmux attachortmux afor short. Generally by habit I typetmux afirst and if no sessions exist then I typetmux.
There are many more features available such as moving panes between windows and sessions, see man tmux.
Sessions can be handled as such,
tmux new -s session_name - creates a new tmux sessiontmux attach -t session_name - attach to a specific sessiontmux ls - list tmux sessionsSelecting and pasting text requires the user to hold SHIFT while selecting text in the terminal on BSD/Linux. In MacOS in iTerm to my knowledge you must type,
To copy in tmux in MacOS
C-b [To paste move the cursor to where you want then type C-b ]. Or if in BSD/Linux while holding SHIFT press middle mouse button.
One useful feature is enabling mouse so you can click between panes, and windows. This can be done as of v2.1.
$ cat ~/.tmux.conf
set -g mouse on
Any changes to
~/.tmux.confrequire you to kill all tmux sessions and restart them to take effect.
With mouse mode enabled you can issue C-b and hold the left mouse button and resize borders as you drag the mouse!
© 2017–2024 David Kalliecharan