Background
tmux is a terminal multiplexer that has many practicalities. I haven’t been using it extensively so whenever I get back to it for
some reason, I need to look up things. There are quite a number of cheatsheets and other sort of resources online but I wanted to
compile a cheatsheet for myself and improve it in time so that I spend less and less time looking up. This is the silly story of
how this cheatsheet came to be.
Having a .tmux.conf file
You don’t know when you may need to overwrite a default configuration of tmux. I think it’s a good idea to create a .tmux.conf
file in your home directory.
Mouse mode
tmux has the option to enable mouse mode. If you’d like to enable mouse mode permanently, add the following line to your
.tmux.conf file but do it with knowing limitations:
set -g mouse on
Now you can switch between your panes and windows using your mouse. You can resize panes as well.
NOTE: However, you will run into issues when copying and pasting texts. With mouse mode on, your selections will behave
differently, you won’t be able to cmd+c to copy the selected text into the system clipboard. Rather, when you select a text by
dragging your mouse and then release it, tmux will automatically copy the text into the buffer. To paste it, you need to do
(ctrl+b) then ], it’s not the same thing as what you have in the system clipboard which you can paste with cmd+v. So then how
to paste what we have in tmux’s buffer into somewhere else outside tmux? At this point, things are getting complicated and I’d
like to not include those in this cheatsheet. Several solutions are available around, do your own research.
- If you want to enable it only for the current session:
(ctrl+b) then :, typeset mouse onandenter
Windows
-
Create a new window:
(ctrl+b) then c -
Rename current window:
(ctrl+b) then , -
Switch to the window by number:
(ctrl+b) then 0..9 -
Close (and kill the processes inside) the window:1
(ctrl+b) then &
Panes
-
Create a new pane horizontally:
(ctrl+b) then % -
Create a new pane vertically:
(ctrl+b) then " -
Switch to the pane by direction:
(ctrl+b) then arrows←↑→↓ -
Resize current pane by direction:2
(ctrl+b) + arrows←↑→↓ -
Make a pane full-screen and back (toggle pane zoom):
(ctrl+b) then z -
Close (and kill the processes inside) the pane:1
(ctrl+b) then x
Scroll and search
To navigate through the history of a tmux pane/windows you need to:
- Enter copy-mode with
(ctrl+b) then [and scroll witharrows↑↓ orPgUp/PgDn - Just scroll with your mouse if you have mouse mode enabled.
tmuxautomatically enters copy-mode when scrolling with mouse.
To search for a term in pane/windows history:
- Enter copy mode either with
(ctrl+b) then [or scrolling with mouse (if enabled) - Use
ctrl+sand type the term you want to search when prompted. To keep searching, keep pressingctrl+s.
History limit
There is a limit to the number of lines you can scroll back and search. In tmux, the defualt is 2000 lines. For me, this
was not enough in most cases, so I prefer to increase it. To increase this limit, to 8000 let’s say, you can add the following
line to your .tmux.conf file:
set-option -g history-limit 8000
Note that a high value limit can strain the memory if you’re creating a lot of panes/windows.
More?
This is it for now. This cheatsheet is definitely not complete but it’s a good start. I want to add more and improve it in time until it’s not noisy but also not lacking any essentials.
Further resources
- ippsec makes very good use of
tmux: https://www.youtube.com/watch?v=Lqehvpe_djs - https://tmuxcheatsheet.com
- https://www.pluralsight.com/resources/blog/cloud/tmux-cheat-sheet
-
You can, indeed, just write
exitto close/kill a window or a pane but you never know when you’ll have a hanging process and there are more things you may have difficulties with exiting other thanvim. ↩︎ ↩︎ -
For some reason, resizing my vertically split panes was working but the other one wasn’t. I haven’t spent much time on the issue but mouse mode helped here. ↩︎