Configuring Tmux for a better work experience

Introduction

Welcome to this blog where I will be taking you through certain steps to get your own tmux configuration. First of all, Let's see What is Tmux? and Why is it used?. Tmux stands for Terminal Multiplexer and is used in Unix-like operating systems. It allows to use multiple terminal sessions in the terminal window. Even if the actual terminal window closes, the tmux session runs in the background and can be accessed with the name of the session, which is helpful when we accidentally close the session without saving the changes.

Here is how we can use tmux:

In the above video, I opened up a tmux session, created three split panes, created a tmux window and then and closed the terminal window and accessed back with the name of the session that I named as "test".

The default configuration for tmux is good but we can add our own plugins to it like colorschemes, custom keybinds and much more. Configuring tmux is not a tough job and is relatively easy. I use a simple minimal tmux configuration and I will take you through the steps on how to achieve them.

Getting Started

So to begin with, we need to know where the tmux configuration file is located at. It is usually located in the home directory as ~/.tmux.conf

Enter the file with your favourite code editor.

The first part to configure tmux is to create a shortcut key to source the tmux config file, by doing so we do not have to quit the file everytime and log in back to the file for the changes to take place. The first two line of the file is:


unbind r # This line unbinds 'r' 
bind r source-file ~/.tmux.conf
# This line binds r again and when combined with "CTRL + B, r" it sources the file with the changes
          

Rebinding the default prefix

In Tmux, the default tmux prefix shortcut key is "CTRL + B" with which you combine them with other keys for the respective tasks and functions.

Now in the standard, it is not ergonomic to press "CTRL + B" so I am using "CTRL + S" as the prefi shortcut so its convenient for me. You can either use the default or you can use any prefix of your own choice

Now the file would look somewhat like this:


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

set -g prefix C-s # We are assigning the prefix in this line

          

Adding mouse support

By default, tmux does not support mouse. So, it is completely keyboard-driven. But for some, it might get hard to get used to the keybinds. So we are going to add mouse support to tmux in the next line


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

set -g prefix C-s 

set -g mouse on # Adding mouse support
          

Setting tmux status bar position

In this step, we are going to set the position of the tmux bar at the top so it does not clash and confuse us with the Vim status bar.


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

set -g prefix C-s 

set -g mouse on

set-option -g status-position top
#Setting status bar position at the top
          

Installing Tmux package manager to install plugins

At every step, resource the file so that changes take place and check whether the changes actually take place by testing them out.

In this step, We are going to install a package manager to install plugins for tmux which requires for us to clone a GitHub repo

Tmux Plugin Manager: https://github.com/tmux-plugins/tpm

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Execute the above command to clone the GitHub repo to install the Tmux Plugin Manager.

Copy the below code snippet which is from the GitHub repo to include the plugins using tmux plugin manager.


# 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' # This line sources the plugins from the ~/.tmux/plugins directory
      

Adding colorscheme

In this step we are going to add the color scheme and to include a plugin we can include them under the "# List of plugins" line. I use the nord colorscheme all over my Linux configuration, so I will go with nord color scheme. You can choose from a variety of colorschemes and plugins. I'll leave a link down which has almost all the list of plugins.


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

set -g prefix C-s 

set -g mouse on

set-option -g status-position top 

# List of plugins

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin "nordtheme/tmux" # Adding the colorscheme


# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm' # This line sources the plugins from the ~/.tmux/plugins directory
      

Conclusion


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

set -g prefix C-s 

set -g mouse on

set-option -g status-position top 

# List of plugins

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin "nordtheme/tmux" 


# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
      

This is our final tmux config file. I hope you got your own config that fits you too.

Here is the GitHub repo that contains all the tmux plugins

List of Tmux Plugins: https://github.com/rothgar/awesome-tmux?tab=readme-ov-file

Hope this blog has helped you to get a starter tmux configuration and if you liked it, please do follow up on the blogs I post. :)

Thank you for reading this blog