You are on page 1of 14

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname

attach:

tmux a # (or at, or attach)

attach to named:

tmux a -t myname

list sessions:

tmux ls

kill session:

tmux kill-session -t myname

Kill all the tmux sessions:

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

In tmux, hit the prexctrl+b(my modied prex is ctrl+a) and then:

Sessions

:new<CR> new session


s list sessions
$ name session

Windows (tabs)

c create window
w list windows
n next window
p previous window
f find window
, name window
& kill window

Panes (splits)
% vertical split
" horizontal split

o swap panes
q show pane numbers
x kill pane
+ break pane into window (e.g. to select text by mouse to copy)
- restore pane from window
space - toggle between layouts
<prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane)
<prefix> { (Move the current pane left)
<prefix> } (Move the current pane right)
<prefix> z toggle pane zoom

Sync Panes

You can do this by switching to the appropriate window, typing your Tmux prex (commonly Ctrl-B or Ctrl-A)
and then a colon to bring up a Tmux command line, and typing:

:setw synchronize-panes

You can optionally add on or o to specify which state you want; otherwise the option is simply toggled. This
option is specic to one window, so it wont change the way your other sessions or windows operate. When
youre done, toggle it o again by repeating the command.tip source

Resizing Panes

You can also resize panes if you dont like the layout defaults. I personally rarely need to do this, though its
handy to know how. Here is the basic syntax to resize panes:

PREFIX : resize-pane -D (Resizes the current pane down)


PREFIX : resize-pane -U (Resizes the current pane upward)
PREFIX : resize-pane -L (Resizes the current pane left)
PREFIX : resize-pane -R (Resizes the current pane right)
PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells)
PREFIX : resize-pane -U 20 (Resizes the current pane upward by 20 cells)
PREFIX : resize-pane -L 20 (Resizes the current pane left by 20 cells)
PREFIX : resize-pane -R 20 (Resizes the current pane right by 20 cells)
PREFIX : resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
PREFIX : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)

Copy mode:

Pressing PREFIX [ places us in Copy mode. We can then use our movement keys to move our cursor around
the screen. By default, the arrow keys work. we set our conguration le to use Vim keys for moving
between windows and resizing panes so we wouldnt have to take our hands o the home row. tmux has a vi
mode for working with the buer as well. To enable it, add this line to .tmux.conf:

setw -g mode-keys vi

With this option set, we can use h, j, k, and l to move around our buer.

To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isnt very
ecient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buer.

For example, we can use "w" to jump to the next word and "b" to jump back one word. And we can use "f",
followed by any character, to jump to that character on the same line, and "F" to jump backwards on the
line.

Function vi emacs
Back to indentation ^ M-m
Clear selection Escape C-g
Copy selection Enter M-w
Cursor down j Down
Cursor left h Left
Cursor right l Right
Cursor to bottom line L
Cursor to middle line M M-r
Cursor to top line H M-R
Cursor up k Up
Delete entire line d C-u
Delete to end of line D C-k
End of line $ C-e
Goto line : g
Half page down C-d M-Down
Half page up C-u M-Up
Next page C-f Page down
Next word w M-f
Paste buffer p C-y
Previous page C-b Page up
Previous word b M-b
Quit mode q Escape
Scroll down C-Down or J C-Down
Scroll up C-Up or K C-Up
Search again n n
Search backward ? C-r
Search forward / C-s
Start of line 0 C-a
Start selection Space C-Space
Transpose chars C-t

Misc

d detach
t big clock
? list shortcuts
: prompt

Congurations Options:

# Mouse support - set to on if you want to use the mouse


* setw -g mode-mouse off
* set -g mouse-select-pane off
* set -g mouse-resize-pane off
* set -g mouse-select-window off

# Set the default terminal mode to 256color mode


set -g default-terminal "screen-256color"

# enable activity alerts


setw -g monitor-activity on
set -g visual-activity on

# Center the window list


set -g status-justify centre

# Maximize and restore a pane


unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp

Resources:

tmux: Productive Mouse-Free Development


How to reorder windows

Notes:
Changelog:

1411143833002 - Addedtoggle zoomunder Panes (splits) section.


1411143833002 -Added Sync Panes
1414276652677 -Added Kill all tmux sessions
1438585211173 -corrected create and add next and previus thanks to @justinjhendrick

Request an Update:

We Noticed that our Cheatsheet is growing and people are coloberating to add new tips and tricks, so please
tweet to me what would you like to add and let's make it better!

Twitter:@MohammedAlaa

ravooricommentedon 17 Apr 2013

Under the Panes section, shouldn't the 'o' key correspond to switch panes and not swap panes?

goatgcommentedon 20 Apr 2013

% is vertical split
" is horizontal

Great cheatsheet!!!

ehellmancommentedon 22 Apr 2013

I still don't understand how to resize panes. The default prex is C-b, then what?

" PREFIX : resize-pane -R (Resizes the current pane right) " , I don't get it. Can anyone help? :)

nickdtoddcommentedon 24 Apr 2013

@ehellmanThis confused me too. You need to do C-b then a colon. This will bring up a bar where you can write resize-panes
with whatever ags you want. Good luck!

rawzonecommentedon 2 Jul 2013

In tmux-1.8 C-b z does a zoom/maximize of active pane (kind of like your Maximize and restore a pane thingy, i guess).

MohamedAlaacommentedon 11 Aug 2013 Owner

@goatgThanks for the comment I xed the the pane horizontal and vertical shotcuts

MohamedAlaacommentedon 11 Aug 2013 Owner

@ehellmanas@nickdtoddexplained the "PREFIX" isctrl+bor depending on your tmux congurations i personally changed
my prex to bectrl+amuch faster :)

todgrucommentedon 16 Aug 2013

Reload the tmux cong le from shell:


$ tmux source-file ~/.tmux.conf

Or from tmux command line:

:source-file ~/.tmux.conf

Atcoldcommentedon 22 Nov 2013

Awesome! Thanks indeed for these tips!

anthonybrowncommentedon 8 Dec 2013

Nice!

bernardrcommentedon 29 Dec 2013

Awesome!Thanks!

MohamedAlaacommentedon 31 Dec 2013 Owner

@todgruI personally have in my .tmux.conf

unbind r
bind r source-file ~/.tmux.conf; display "Reloaded"

this way when i use thePREFIX + rit loads

joestringercommentedon 6 Feb 2014

Resizing down seems to require the "-D" option for me (tmux-1.6):

PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells)

kocsenccommentedon 10 Feb 2014

Use it every day. Amazing Cheatsheet

jtanmaycommentedon 14 Mar 2014

thanks! helped a lot :)

tdoumascommentedon 21 Mar 2014

Thank you! Very useful

bradleyankromcommentedon 1 Jun 2014

Looks like the cheat sheet link is dead :(http://cheat.errtheblog.com/s/tmux/

MohamedAlaacommentedon 4 Jun 2014 Owner

thanks@bradleyankromI removed the link to the cheat :)


i90rrcommentedon 20 Jun 2014

Running tmux 1.8, same behaviour as described by@joestringer:


"Resizing down seems to require the "-D" option for me"

Btw, nice list to have at hand :)

benoptimuscommentedon 8 Jul 2014

thank you for sharing this, very useful!!

rushiagrcommentedon 12 Jul 2014

Thanks. Useful.

gavsimcommentedon 14 Jul 2014

Very useful, greatly appreciated.

giangnguyennetcommentedon 19 Jul 2014

It's strange I can't resize the panes in tmux. For example to resize left a pane, I tried:

^b ^h
^b alt-<arrow-left>
^b ^<arrow-left>

This works

^b : resize-pane -L

but I prefer a shortcut to having to type too much.

Any ideas?

ps: I don't have ~/.tmux.conf le

fkenjicommentedon 11 Aug 2014

@ndgiang84 If you are on MacOS you can try this out:http://superuser.com/questions/660013/resizing-pane-is-not-working-


for-tmux-on-mac

hienvdcommentedon 12 Aug 2014

Thank for your tips.


Btw, how can I change the default PREFIX (CTRL+B) to another key?

Drive137commentedon 12 Aug 2014

@hlenvd you can I do


set-option -g prex C-a
unbind C-b
bind-key C-a send prex
in the tmux.cong
source -http://robots.thoughtbot.com/a-tmux-crash-course

toorehtcommentedon 17 Aug 2014

Thank you for this awsome cheatsheet!


What about adding@rawzone's zoom command to the Panes section?

z toggle (zoom) active pane to full terminal size

MohamedAlaacommentedon 19 Sep 2014 Owner

Updated The following

Added the toggle zoom command


Added The Sync Panes trick

You ask for updated by sending me a tweet@MohammedAlaa

MohamedAlaacommentedon 26 Oct 2014 Owner

Updated The following

Added kill all tmux sessions

You ask for updated by sending me a tweet@MohammedAlaa

MrWonderfulcommentedon 28 Oct 2014

I had a problem running your kill-all command as an alias, but I found this one worked well for me:

alias tmkill='while [ $? -ne 1 ]; do tmux kill-session; done'

quizzmastercommentedon 5 Nov 2014

To resize a pane down:

PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells)

shropcommentedon 8 Dec 2014

Best cheat sheet for tmux I have seen. Posted onhttp://shelldevel.net/post/104491784292/mohamedalaa-tmux-cheatsheet-


markdown

wbnnscommentedon 10 Jan 2015

Thanks for putting this together. :)

nooitafcommentedon 17 Jan 2015

Show a list of the messages tmux displayed in the lower bar:

prefix + ~

jacktasiacommentedon 18 Feb 2015

@MohamedAlaaI believe@ravooriis correct. It should be like this instead:

Panes (splits)

o switch to next pane


C-o swap panes

It's easy to confuse these because if you accidentally keep holding control down from doing your prex then you'll be doing
swap instead of next.
rakgeniuscommentedon 23 Feb 2015

I have problem switching between last used session. C-a L switches to last used window rather than last used session which is
the same as C-a l. Is there a way to switch to last used session?

bobeirasacommentedon 19 Apr 2015

I'm laughing for myself about the mouse support, like a children with a new lollipop, I just can't believe how AWESOME it is.

nladdcommentedon 8 May 2015

Thanks! Exactly what I needed

LukasMaccommentedon 16 May 2015

When in copy mode I ndShift + jandShift + kvery usefull: text scrolls up/down while maintaining cursor position

VladSemcommentedon 22 May 2015

just type in terminal man tmux

zaynetrocommentedon 16 Jul 2015

Can anyone tell me how to edit current command in tmux? I use vi bindings and want to be able to edit the command I am
currently specifying.

thuannvncommentedon 20 Jul 2015

tks

justinjhendrickcommentedon 28 Jul 2015

Consider these edits?https://gist.github.com/justinjhendrick/51dcf569322675ceeacf

I changed "new window" to "create window", so that it's easier to remember.


I added "next window" and "previous window".

grahamgcommentedon 3 Aug 2015

Thanks for this great reference sheet Mohamed!

j0hnsmithcommentedon 15 Sep 2015

Great cheat sheet, something is missing...

"we set our conguration le to use Vim keys for moving between windows and resizing panes so we wouldnt have to take
our hands o the home row"

Can you add that?

fuzzyweaponcommentedon 16 Sep 2015

One thing you could do to support the growing collaboration is make this a repo instead of a gist.
This /will/ backre for people who use gist ide plugins and tools to quickly access documentation (aka, use gists as a personal
documentation platform), but you could easily setup a CI workow based on webhooks that publishes to the gist when a PR is
merged into the repo.

Then people can do PRs, submit requests via issues, report outdated information via issues, etc, however you wanted to
handle it.

chenqingcommentedon 17 Sep 2015

so nice

ttpearscommentedon 19 Oct 2015

The kill all sessions didn't work for me, this does:
for sess in $(tmux ls | awk '{FS=":" ; print $1}' | sed 's/://g') ; do tmux kill-session -t $sess ; done

retrautcommentedon 22 Oct 2015

Thx for that

gusgardcommentedon 4 Nov 2015

In Congurations Options. Tmux 2.1 dont support

setw -g mode-mouse o
set -g mouse-select-pane o
set -g mouse-resize-pane o
set -g mouse-select-window o

instead use:

*set -g mouse on

Enverexcommentedon 13 Nov 2015

Creating a new pane is quite possibly one of the most important controls but I don't see the key commands to do it here?

ChiChoucommentedon 15 Nov 2015

@Enverexdid you mean splitting current window into multiple panes? SeePanes (splits)

dragon788commentedon 19 Nov 2015

@MohamedAlaaThis sounds like a great set of exercises for shortcutfoo.com's tmux setup. Now that you can create your
own exercises I may have to work o this list to expand my knowledge.

AbhimanyuAryancommentedon 22 Nov 2015

Thanks.

dautovricommentedon 23 Dec 2015

Thank you!

Ryan4021commentedon 29 Dec 2015

This is great, thanks!


marzkcommentedon 13 Jan 2016

+ break pane into window (e.g. to select text by mouse to copy)is error.

! Break the current pane out of the window.


tmux

FrozenBeardcommentedon 26 Jan 2016

I found this out by mistake, but doing CTRL+D during a tmux session kills it (Very helpful!)

tiborsimoncommentedon 1 Feb 2016

PREFIX : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)

Didn't you miss the pane id after the-t?

zjkikicommentedon 17 Feb 2016

kill all sessions just use "killall tmux", it's quick :)

numistcommentedon 24 Feb 2016

Also useful:select-layout even-horizontalandselect-layout even-verticalfor when you've buggered your (one-dimensional)


pane layout by resizing your terminal window.

sminranacommentedon 5 Mar 2016

Thanks for sharing this.

luofei2011commentedon 9 Mar 2016

kill all the tmux sessions.

for session in `tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}'`;do tmux kill-session -t ${sessi

takacsmarkcommentedon 31 Mar 2016

Thanks, great cheat sheet. I'm missing a basic shortcut to move between panes. Besidesprefix + oyou can useprefix + the
arrow keysto move up, down, left, right from one pane to the other. It makes you more productive.

easydevmixincommentedon 6 Apr 2016

Just what I was looking for! Thanks!

I'd like to add, just in case a pane freezes out:

PREFIX : kill-pane -t <pane number>

coreydaleycommentedon 10 Apr 2016

This command did not work for me on tmux 1.8:


tmux a #
I had to use
tmux a -t #
To connect to a non-named session

Flowdeepscommentedon 24 May 2016

ctrl-b esc [1 to 5] moves your current panes to dierent layouts. Which I do all the time due to using IRSSI. Is there a way of
setting your current layout conguration as default?

ZeBigDuckcommentedon 25 May 2016edited

I added a function in .zshrc to be able to toggle between sessions :

function tmux_switch_session() {
setxkbmap fr;
xdotool keyup Alt_L && xdotool key "Control_L+b";
xdotool type --clearmodifiers ":a -t $(tmux ls | grep : | cut -d: -f1 | sed -n $($(exit $(tmux ls | wc -l)!=$(tmux ls | g
xdotool key "KP_Enter";
}

zle -N tmux_switch_session;
bindkey "^[s" tmux_switch_session;

Now, just press Alt+s to go to next session


(note you have to change keyboard locale with your own locale)

Wasn't able to make a tmux shortcut (xdotool sendsCtrl+b, thenls, thenEnter, then:...)

ThisIsJohnBrowncommentedon 12 Aug 2016

Just want to reiterate@gusgard's comment. The mode for mouse is now simply:setw -g mouse on

leanhtiencommentedon 22 Aug 2016

Thank you guy :)

Aminadavcommentedon 10 Oct 2016

Easier way to kill all sessions:

tmux ls | cut -d: -f1 | xargs -l1 tmux kill-session -t

luoyupingcommentedon 16 Oct 2016

this is wrong , you should not treat the tmux session as a normal process,so 'kill' will not work

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

emersonxsucommentedon 9 Nov 2016

AminaG's solution is correct but luoyuping's killing sessions' way is not working on my remote devserver.

grantcarthewcommentedon 29 Nov 2016

Why not make this a full repo rather than a gist? Then we can send in PRs.

mirzalazuardicommentedon 8 Dec 2016edited

I trapped to this page when googled how to resize panes .this is very usefull. thanks alot
ryrancommentedon 22 Dec 2016

Panes can be resized without ridiculous commands by using:PREFIX,Ctrl-arrow...


E.g.:Ctrl-b,Ctrl-UP,UP,UP,UP.

lmj0011commentedon 31 Dec 2016

@ryran
thanks for that!

nguyenduyhao1111commentedon 31 Dec 2016

Thanks you!

apurvaguptacommentedon 30 Jan

Is there any way to identify which pane is running what? for example, I am running 10 servers in dierent pane then can I
identify which pane is running what server ?

tonycommentedon 16 Feb

(Note: I posted this to a couple of other gists related to tmux.)

I recently nished a book on tmux,The Tao of tmux. It's available toread on the web for free. The book includes a cheatsheet
section, in addition to covering tmux from the ground up via its session, window and pane objects. I also go into some tricks
for optimizing workows in the world of the terminal. Please feel free to give it a look!

Tony

leotmcommentedon 1 Maredited

Kill all the tmux sessions:tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs killdidn't work
for me.

Butkillall tmuxdid the job.

scutdkcommentedon 18 Maredited

Sync pane is what I am looking for, but it's not so intuitive. Just add a reminder: Sync pane is to duplicate input to any pane to
all other panes in the same window (only for panes that are not in any special mode). Maybe can add this after the title so
even rst timer knows what it means.

One more note, sync pane mode doesn't work in vim. So only way to modify multiple les is to use sed instead.It's working,
just only cursor in the main pane is blinking. :D

LovesThacommentedon 24 Mar

I can't split horizontal, " brings up a list of tmux screens for me, which is rather useless.

cocampbecommentedon 25 Apr

Wholly cow! DO NO USE the kill all tmux sessions shortcut. Your sending tmux session IDs to the kill command. Use this
instead.

tmux ls | awk -F: '{print $1}' | xargs -i tmux kill-session -t {}

smithanagcommentedon 28 Apr
How to search for a text in tmux window?

Siva-Karthicommentedon 19 May

Awesome

deavmicommentedon 26 May

So helpful.

SeattleRexcommentedon 11 Jun

'tmux kill-server' kills all sessions and gives you a fresh start

backwind1233commentedon 12 Jun

very useful

LMtxcommentedon 16 Junedited

@MohamedAlaa
hello, mouse section is outdated - you can update it from my fork

OmarMalikcommentedon 20 Jun

When I have multiple tmux windows open and I resize one, it starts resizing all of them together. How do i disable this? This is
on a mac btw.

0xnurlcommentedon 10 Jul

Thank you so much

Shaddycommentedon 6 Aug

This is the bash-script I use when I want to kill all the sessions except the attached.

Kill all sessions except attached


tmux ls | awk '$1 gsub(":", "") {if (!/attached/) system("tmux kill-session -t " $1)}'

Not sure why thekill allscript requires grep + cat + awk + xargs, I would write it as this.

Kill all sessions simplied


tmux ls | awk '$1 gsub(":", "") {system("tmux kill-session -t " $1)}'

Atlas7commentedon 20 Aug

I use this cheatsheet pretty much every single time I use a terminal! Life saver... !

harpreetsc1992commented21 days agoedited

I think the options in the new tmux versions has changed.


For example:
set mouse on
turns all mouse options on.
jobwatcommented2 days agoedited

When the window is stuck in a smaller dimension (due to a former session on a smaller screen):

:detach -a

You might also like