Now that we have a good understanding of how to manage sessions, windows and panes, let's learn how to customize
A good habit to form is to always have
tmux running whenever you open a shell. We can have tmux run upon startup by adding this snippet into our ~/.bash_profile
if [[ ! $TERM =~ screen ]]; then tmux attach -t base || tmux new -s base fi
tmux's system-wide settings on a Linux system, edit the /etc/tmux.conf file. For more user-specific settings, edit ~/.tmux.conf.
To reload the configuration file, type:
$ tmux source-file ~/.tmux.conf
You can also bind the
r key to easily reload as a keystroke. Place the following in your ~/.tmux.conf file:
bind r source-file ~/.tmux.conf
One of the first things users can do is to change the prefix key from <Ctrl-b> to <Ctrl-a>. Now that we know how to rebind the prefix key, we'll refer to your binding as prefix instead of Ctrl-b.
# Sets the prefix to Ctrl-a set -g prefix C-a # Releases binding from Ctrl-b unbind C-b bind C-a send-prefix
The -g indicates a global preference, meaning it applies all around
It could be cumbersome having to use the prefix key every time you want to switch panes.
bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D
The M is the meta key (oftentimes the alt-key). Now you can simply hold onto alt+[Up/Down/Left/Right] to move among panes.
Sometimes you'll miss those GUI mouse-activated controls. We can re-active them using these three mouse modes:
# Enable mouse control set -g mouse-select-pane on set -g mouse-resize-pane on set -g mouse-select-window on
Now you can:
You can also configure the status line to select what it should display, and whether it should be on or off.
You can set the date with variables from strftime. For example, %c will display the date and time.
set -g status-right "Code Snipcademy %c" set -g status-bg white set -g status-fg black
We have a color choice among black, red, green, yellow, blue, magenta, cyan, white or default.
You can also use the following variable keys for a more dynamic status bar.
If you're anything like myself, you may find it difficult to remember that % is for splitting horizontally and " is for splitting vertically. We can map the commands to - and | instead.
unbind % unbind '"' bind | split-window -h bind - split-window -v
Plugins are a fast and easy way to obtain features without writing tens of lines of code. In fact, most of what we configured above are covered in some plugin. Let's learn how to install the tmux-pain-control plugin as an example. Feel free to browse through the list of tmux plugins for more plugin ideas.
To get started, download the tmux Plugin Manager (tpm):
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
You will now be set to install any plugins.
Now open ~/.tmux.conf with Vim:
set -g @tpm_plugins ' \ tmux-plugins/tpm \ tmux-plugins/tmux-pain-control \ ' run-shell '~/.tmux/plugins/tpm/tpm'
To install the plugin, place your cursor over the plugin, then press prefix I. You should get a window pop up like this (except with install statuses):
With this plugin, we can:
Remember that if there's a good nifty shortcut or trick, there's most likely a plugin for it. If you have a good idea for customization, try first looking for a plugin - it'll make your life easier!
What's your favorite configuration or plugin? Share in the comments below!
Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.$ Check price
This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.$ Check price