Vous êtes sur la page 1sur 7

16/09/2017 A tmux Crash Course

All Topics Design Web iOS Android

A tmux Crash Course


Josh Clayton January 18, 2011 UPDATED ON January 16, 2016
TMUX , UNIX , VIM

Ive been using tmux for about six months now and it has become just as essential to my
workflow as vim. Pane and window management, copy-mode for navigating output, and
session management make it a no-brainer for those who live in the terminal (and
especially vim). Ive compiled a list of tmux commands I use daily to help me work more
eiciently.

https://robots.thoughtbot.com/a-tmux-crash-course 1/7
16/09/2017 A tmux Crash Course

Shortcuts

If a tmux command I mention is bound to a keyboard shortcut by default, Ill note that in
parenthesis.

Theyre accessed by entering a key combination called the prefix and then typing a letter.

For example, if you see prefix + d below, that means you would first hit (and release)
Control + b and then type d .

The prefix can also be changed, which Ill show you how to do later.

Session Management

Sessions are useful for completely separating work environments. I have a Work session
and a Play session; in Work, I keep everything open that I need during my day-to-day
development, while in Play, I keep open current open-source gems or other work I hack
on at home.

tmux new -s session_name


creates a new tmux session named session_name

tmux attach -t session_name


attaches to an existing tmux session named session_name

tmux switch -t session_name


switches to an existing session named session_name

tmux list-sessions
lists existing tmux sessions

tmux detach (prefix + d)


detach the currently attached session

Windows

https://robots.thoughtbot.com/a-tmux-crash-course 2/7
16/09/2017 A tmux Crash Course

tmux has a tabbed interface, but it calls its tabs Windows. To stay organized, I rename all
the windows I use; if Im hacking on a gem, Ill name the window that gems name. The
same thing goes for client applications. That way, I can recognize windows by context and
not what application its running.

tmux new-window (prefix + c)


create a new window

tmux select-window -t :0-9 (prefix + 0-9)


move to the window based on index

tmux rename-window (prefix + ,)


rename the current window

Panes

Panes take my development time from bland to awesome. Theyre the reason I was able to
uninstall MacVim and develop solely in iTerm2. I dont have to switch applications to
switch contexts (editing, reading logs, IRB, etc.) - everything I do, I do in a terminal now.
People argue that OS Xs Cmd+Tab is just as fast, but I dont think so.

tmux split-window (prefix + ")

splits the window into two vertical panes

tmux split-window -h (prefix + %)


splits the window into two horizontal panes

tmux swap-pane -[UDLR] (prefix + { or })


swaps pane with another in the specified direction

tmux select-pane -[UDLR]


selects the next pane in the specified direction

tmux select-pane -t :.+


selects the next pane in numerical order

https://robots.thoughtbot.com/a-tmux-crash-course 3/7
16/09/2017 A tmux Crash Course

Helpful tmux commands

tmux list-keys
lists out every bound key and the tmux command it runs

tmux list-commands
lists out every tmux command and its arguments

tmux info
lists out every session, window, pane, its pid, etc.

tmux source-file ~/.tmux.conf


reloads the current tmux configuration (based on a default tmux config)

Must-haves

These are some of my must-haves in my tmux config:

# remap prefix to Control + a


set -g prefix C-a
unbind C-b
bind C-a send-prefix

# force a reload of the config file


unbind r
bind r source-file ~/.tmux.conf

# quick pane cycling


unbind ^A
bind ^A select-pane -t :.+

Workflow

During the day, Ill work on one or two Rails apps, work on my dotfiles, run irssi, and maybe
run vim in another window to take notes for myself. As I mentioned, I run all of this inside
one tmux session (named work) and switch between the dierent windows throughout
the day.

https://robots.thoughtbot.com/a-tmux-crash-course 4/7
16/09/2017 A tmux Crash Course

When Im working on any Ruby work specifically, Ill have a 75%/25% vertical split for vim
and a terminal so I can run tests, interact with git, and code. If I run tests or git diff
and want to see more output than the 25% allots me, Ill use tmux to swap the panes and
then move into copy mode to see whatever I need to see.

Finally, I run iTerm2 in full-screen mode. Switching between OS X apps for an editor and a
terminal is for chumps!

Whats next

If you found this article useful, you might also enjoy:

Seamlessly Navigate Vim and tmux Splits

tmux Copy and Paste on OS X

Running Specs from Vim, Sent to tmux via Tslime

Take control of your terminal and build your ideal development workflow. The
tmux course on Upcase will teach you the ins and outs of tmux for terminal
mastery.
https://robots.thoughtbot.com/a-tmux-crash-course 5/7
16/09/2017 A tmux Crash Course

Get Started Free

PRODUCTS

FormKeep
Hound
Upcase

SERVICES

Android
Design
Elixir/Phoenix
Go
iOS
Python/Django
React Native
Ruby/Rails

OPEN SOURCE

Argo
Bourbon
Capybara Webkit
Clearance
Dotfiles
Factory Girl
Laptop
Suspenders
https://robots.thoughtbot.com/a-tmux-crash-course 6/7
16/09/2017 A tmux Crash Course

More...

LOCATIONS

Austin, TX
Boston, MA
London, UK
New York, NY
Raleigh, NC
San Francisco, CA
Washington, DC

PODCASTS

The Bike Shed


Build Phase
Giant Robots
Tentative

2017 THOUGHTBOT, INC.


The design of a robot and thoughtbot are registered trademarks of thoughtbot, inc. Privacy Policy

https://robots.thoughtbot.com/a-tmux-crash-course 7/7

Vous aimerez peut-être aussi