Introduction
This article aims to guide users on setting up tmux keybindings to behave like hjkl keys in Vim. The configuration process is relatively straightforward, and this article will walk you through the steps.
Configuring tmux
First, let's ensure that you have the necessary prerequisites. Install tmux if you haven't already, and make sure it's up-to-date.
Copy mode Vi key tables
The easiest way to set up Vim-like keybindings in tmux is by copying the Vi key tables. These tables are available in the tmux source code and can be easily included in your tmux.conf file.
Steps to configure
- Locate the Vi key tables in the tmux source code. The path may vary depending on your system, but it's usually found in /usr/share/tmux/tmux.conf. If you have tmux installed from a package manager, it might be in a different location.
- Copy the key tables into your personal tmux.conf file, typically located in ~/.tmux.conf.
- Add a prefix to your keybindings. This can be any key combination you prefer, such as C-a (Ctrl+a).
- Configure the keybindings according to your needs. For example, you can set up hjkl keys as follows:
Example configuration
# vi-mode bindings
setw -g mode-keys vi
bind-key -T vi-mode h begin-selection
bind-key -T vi-mode j down
bind-key -T vi-mode k up
bind-key -T vi-mode l end-selection
With these simple steps, you can now enjoy a Vim-like experience within tmux. Experiment with different keybindings to find a setup that suits your workflow best.