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!
Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.$ Check price
The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.$ Check price