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-bagain if you want to passC-bas is to an application in tmuxcto create a new windownto switch to the next windowpto switch to the previous window'prompt to enter a window index number to switch to0–9switch to the numbered windowwinteractively 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
spaceto start selecting text andenterto copy the selection into tmux’s buffers - press
qto 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-dand find the connection with smaller dimensions and pressEnterto 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 sessionssinteractively choose a session to connect to (a session contains windows & panes)%split the current window into left & right panesoswitch 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
SHIFTand make a selection with the mouse. Then use the usual terminal copy shortcut (Ctrl+Shift+cin my case to copy the selection).
