Tmux has forever changed the way I write code.

Tmux Has Forever Changed the Way I Write Code
Tmux is perhaps the one piece of software that's had the biggest impact on the way I write code. Out of the box, however, tmux can be difficult to look at—it requires a little bit of configuration to really get productive with. In this article, I'm going to explain why tmux is so powerful and show you how to update it from its default offering into a version that is modern, zenful, and a joy to work with.
Why Tmux Changed Everything for Me
I really meant it when I said that tmux has had one of the biggest impacts on the way I write code. Before discovering it, I worked more with IDEs and graphical editors and only entered the terminal when I needed to. Once I discovered tmux, however, that all changed. My default editor became Neovim, and I was able to have all of the goodness of a tiling window manager in the terminal.
Tmux also provides other features for working in a command line that I just can't live without. Using tmux, I can:
- Create and manage new windows for multiple terminal sessions
- Split a window into panes so that I can have multiple sessions in one view
- Prevent my workspace from being lost if my terminal crashes (or more likely, if I accidentally close it)
- Pick up my laptop, SSH into my desktop, and attach into my previous tmux session for some nighttime bed coding
Tmux really has improved the way I work, and over the years I've built up a configuration that works really well for me, which I want to share with you today.
Getting Started with Tmux
Before we can start writing our zenful configuration, we need to do a little setup work.
Prerequisites
First, make sure you have tmux installed. As of the time of this writing, the latest version is 3.3a. Get that installed as per your operating system.
Next, you're going to need the Tmux Package Manager (TPM). This is installed using git, so make sure you have that as well. To install the tmux package manager, you can run the following command:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Creating Your Configuration File
Now let's create our tmux config file. You can do this at either:
~/.tmux.conf
, or$XDG_CONFIG_HOME/tmux/tmux.conf
(which typically translates to~/.config/tmux/tmux.conf
)
I'm going to go with the XDG config as it's the more modern way to manage dot files.
Next, open up your fresh config file in your favorite editor and add in the following lines to source the TPM package and run it:
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
While we're here, we're also adding in the sensible package, which basically sets a number of options that fix some of the quirks with tmux's default configuration. If you want to know more about what options this package changes, I recommend heading over to the GitHub page and reading their documentation.
With our initial config set, we can go ahead and run tmux to load it. If you're already in tmux, you can reload the configuration by running:
tmux source ~/.config/tmux/tmux.conf
How to Use Tmux: The Basics
Before we jump into configuring tmux, it's worth going over some of the basic commands and key bindings for using it.
Sessions, Windows, and Panes
Tmux consists of three main objects:
Sessions are the topmost layer in tmux and are a collection of one or more windows managed as a single unit. You can have any number of sessions open at one time but typically only attached to one.
Windows are a container for one or more panes. You can think of windows as tabs in browsers or other software. Each window has a currently active pane and allows you to switch between any of the panes that it manages. The windows in the session are shown at the bottom of the screen, with the currently active window marked with an asterisk.
Panes are splits in the window and represent an individual terminal session. There will only be one active pane at a time that you'll interact with.
The Prefix Key
To enter commands to tmux, you need to use what's called the prefix key. This is a key combination that you use before the actual command itself. The default prefix is Ctrl + B
.
Essential Commands
Window Management
- Create new window:
prefix + c
- Switch between windows:
prefix + [window number]
- Cycle through windows:
prefix + n
(next) orprefix + p
(previous) - Close window:
prefix + &
Pane Management
- Split horizontally:
prefix + %
- Split vertically:
prefix + "
- Navigate panes:
prefix + [arrow keys]
- Swap panes:
prefix + {
orprefix + }
- Show pane numbers:
prefix + q
- Zoom into pane:
prefix + z
- Turn pane into window:
prefix + !
- Close pane:
prefix + x
Session Management
- Create new session:
tmux new -s [session-name]
- List sessions:
tmux ls
(outside tmux) orprefix + s
(inside tmux) - Attach to session:
tmux attach -t [session-name]
- Preview windows:
prefix + w
This covers a lot of the basic commands for tmux, but there are plenty of others. I recommend checking out tmux cheatsheet.com for more commands.
Better Navigation with Vim Keys
After installing the package manager, the first thing I like to do is set up better key bindings for navigating around tmux. I use a package called vim-tmux-navigator, which provides two key features:
- The ability to move around split panes in tmux using
Ctrl + h/j/k/l
keys (similar to Vim navigation) - Seamless integration between tmux and Neovim when you install it as a Neovim plugin as well
Setting Up Vim-Tmux-Navigator
First, add it to your Neovim configuration. Since I'm using NvChad, I add the plugin to my custom plugins file:
{
"christoomey/vim-tmux-navigator",
lazy = false,
}
I also had to add custom mappings to override the ones that NvChad sets, which can interfere with vim-tmux navigation settings.
Now in our tmux config, add the vim-tmux-navigator to our tmux plugins:
set -g @plugin 'christoomey/vim-tmux-navigator'
Install it by using prefix + Shift + I
, then source your tmux configuration. You'll now be able to navigate using Ctrl + h/j/k/l
keys, and this works seamlessly between tmux and Neovim, making them work as if they were one application.
Custom Window Navigation
I also like to add custom mappings for navigating windows. Add these lines to allow cycling across windows using Shift + Alt + H/L
:
bind -n M-H previous-window
bind -n M-L next-window
Fixing Colors
One thing we need to fix is our colors when inside a tmux session. You might notice that colors look different in tmux versus outside of it. Fix this by adding the following line to your tmux config:
set-option -sa terminal-overrides ",xterm*:Tc"
This sets tmux to use 24-bit color, provided that your terminal supports it.
Changing the Prefix Key
So far we've kept the default prefix key binding of Ctrl + B
. However, this binding tends to be used for other functionality in the terminal. I like to change the tmux prefix to Ctrl + Space
instead:
unbind C-b
set -g prefix C-Space
bind C-Space send-prefix
Adding a Beautiful Theme
Finally, it's time to get rid of that horrible green line! Catppuccin is my favorite color scheme, and it provides a plugin for tmux as well. Add it to your configuration:
set -g @plugin 'catppuccin/tmux'
Install it with prefix + Shift + I
. As well as the default color scheme (called "mocha"), you can change this to any of the other variants by setting the Catppuccin flavor variable:
set -g @catppuccin_flavour 'latte' # or frappe, macchiato, mocha
I actually have my own fork of Catppuccin as I prefer to have a little more information on my window tabs. To use my version, change the plugin line to:
set -g @plugin 'dreamsofcode-io/catppuccin-tmux'
Essential Productivity Features
Mouse Support
Enable mouse support to click between windows/panes and scroll through buffer history:
set -g mouse on
Better Window Numbering
By default, tmux starts indexing windows at zero, but the zero key is all the way to the right on a keyboard. Start indexing at one instead:
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on
Improved Copy Mode
The tmux-yank package provides better copying functionality:
set -g @plugin 'tmux-plugins/tmux-yank'
I also like to make copy mode more Vim-like:
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
Now you can:
- Enter copy mode with
prefix + \[
- Press
v
to start selection - Use Vim navigation keys to select
- Press
y
to copy - Toggle rectangle select with
Ctrl + v
Open Panes in Current Directory
Set panes to open in the same directory as the pane you're splitting from:
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
Conclusion
With these configurations, you now have a tmux setup that is both productive and a joy to work with. The combination of better navigation, beautiful theming, and productivity features transforms tmux from a basic terminal multiplexer into a powerful development environment.
I hope this article inspired you to try tmux yourself or upgrade your existing configuration. The complete configuration can be found in my GitHub repository, and if you know of any other plugins that should be included, feel free to share them!
Useful Resources
- Tmux Cheatsheet - Need a tmux cheatsheet? Visit the Dreams of Code Store
- Complete Tmux Config Repository
- Official Tmux Repository
- Tmux Plugin Manager (TPM)
- Dreams of Code Newsletter - Become a better developer in 4 minutes
Want to connect? Join the Discord community or follow on Twitter.