One of the biggest benefits I’ve seen from switching to vim as my primary text
editor is that I can use the same text editor whether I ssh
into a server, or
I use any of my laptops (regardless of operating system). If you’re interested
in learning how I use vim, please check out this old post. To keep my
workflows as similar as possible, I have also started gravitating to
tmux. This post should offer some tips on how to
get started with tmux.
For this tutorial, I’ll use the following notation:
<C-b>
is equivalent to pressing control
and b
at the same time.
prefix
which is used to determine whether a command
is intended for tmux or the terminal running in the tmux session.prefix q
is equivalent to pressing control
and b
at the same time, then
letting them go and pressing the letter q
.If you’ve used emacs before, you’ll find that a lot of the keybindings bear some resemblance. Let’s get started.
Pane
: a pseudo terminalWindow
: A collection of panes that are shown on screen at the same time.
This is similar to what you’d expect to find in a window in an application
like iTerm.
Session
: A collection of windows that are managed by tmux. Sessions can
persist in the background if you lose your connection with the server or
detach from the session.
Using sessions:
$ tmux new
= Creates a new tmux session$ tmux ls
= View current tmux sessions
prefix s
= Navigate between sessions$ tmux attach -t SESSION_NAME
= Attach to an existing tmux sessionprefix $
= Rename a sessionprefix d
= Detach from current sessionWhen you start a new tmux session, a single window with a single pane is created.
This is the end of Part 1 on core concepts.
Now that you have a tmux session, you need to setup up your work environment.
Managing windows:
prefix c
= Creates a new windowprefix n
= Navigate to the next windowprefix p
= Navigate to the previous windowprefix NUM
= Navigate to window at index NUM
prefix &
= Close current windowprefix ,
= Rename current windowprefix w
= Navigate between windows in active sessionsManaging panes:
prefix %
= Creates a new pane by splitting the active pane verticallyprefix "
= Creates a new pane by splitting the active pane horizontallyprefix arrow
= Move between panes in the direction of the arrowprefix x
= Close active paneprefix z
= Make pane full screenprefix q
= Navigate between panes in active windowprefix !
= Split current pane into its own windowResizing and moving panes:
prefix <M-arrow>
= Resize the current paneprefix E
= Spread out the panes evenlyprefix Space
= Select the next default layoutprefix {
= Move pane upprefix }
= Move pane downThis is the end of Part 2 on navigation.
Like with a vimrc
, you can add configurations to your tmux.conf
. Here are
some that you may consider adopting when you’re getting started. To
learn more, you can browse the docs.
# tmux.conf
set -g mouse on # enable mouse scrolling
set -s escape-time 10 # faster command sequences
set -g history-limit 5000 # boost history limit
set -g allow-rename off # don't rename windows automatically
set -g mode-keys vi # use vi keybindings for copy mode
# display "tmux.conf loaded!"
This is the end of Part 3 on configuration.
A key hurdle to me adopting a tmux-based workflow was figuring out how to move data between panes. Now that I know how to use it, I find it much more expressive than using my mouse to select text, and I appreciate having easy access to multiple buffers.
<C-[>
= Enter copy modeq
= Exit copy mode<C-]>
= Paste bufferemacs mode (default)
<C-Space>
= Start selectionR
= Change to rectangle selectionemacs
movements<C-w>
= Copy selectionvi mode (my preference)
Space
= Start selectionv
= Change to visual block modevim
movementsEnter
= Copy selectionMultiple paste buffers
Copied text is placed into a buffer that you can paste later. tmux has the ability to manage multiple buffers. Here are the highlights of how I use them.
<C-=>
= View the paste buffersEnter
or p
= Paste selected bufferd
= Delete selected bufferYou can read more about copy and paste in tmux here.
This is the end of Part 4 on data movement.
Hope this helps get you oriented with tmux. For a quick refresher about the
commands at your disposal, use prefix ?
. For more details, I will sometimes
browse through $ tmux list-keys
to see all of the available keybindings and
$ tmux list-commands
to see all of the commands that can be used. I realize
this is just scratching the surface of how tmux can help improve my workflow.
If you have suggestions on things that I should consider trying, please let me
know. Happy hacking.