Thought I’d make an entry with useful tmux keys as a reference to myself.
Ctrl-b
(also referred to as C-b
) is the prefix for tmux commands. You can change this via .tmux.conf; I left mine at the defaults so I’ll stick with that.
After pressing C-b
you press a key for the actual command you want tmux to do:
C-b
again if you want to passC-b
as is to an application in tmuxc
to create a new windown
to switch to the next windowp
to switch to the previous window'
prompt to enter a window index number to switch to0
–9
switch to the numbered windoww
interactively choose a window to switch to
:
enter the tmux command prompt where you can enter commands[
enter copy mode – this lets you scroll around the history with your arrow keys. This will scroll out of the application window if you go too much up.- when in this mode press
space
to start selecting text andenter
to copy the selection into tmux’s buffers - press
q
to quit copy mode
- when in this mode press
]
paste the most recently copied text (from tmux’s buffer)D
(shift-d
) interactively select a client to detach- This is useful when you connect to a session from a larger screen and tmux doesn’t resize the window as the remote client of smaller dimensions is still connected. You simply do
C-b S-d
and find the connection with smaller dimensions and pressEnter
to disconnect it.
- This is useful when you connect to a session from a larger screen and tmux doesn’t resize the window as the remote client of smaller dimensions is still connected. You simply do
Others that I haven’t used much but worth a mention
(
and)
to switch to the previous and next sessionss
interactively choose a session to connect to (a session contains windows & panes)%
split the current window into left & right paneso
switch to the previous pane (I couldn’t find one to switch to the next pane; good I guess, one less key to remember!){
and}
swap the current pane with the previous or next panes
A note about copy-paste
- When using iTerm2 on the Mac, I can copy a selection of text in a tmux session and it copies it to the Mac clipboard. This is because I told iTerm2 it is ok for terminal applications to access the clipboard.
- I couldn’t find a similar option in the GNOME Terminal or Xfce Terminal. So here I press
SHIFT
and make a selection with the mouse. Then use the usual terminal copy shortcut (Ctrl+Shift+c
in my case to copy the selection).