Neovim is a powerful and feature-rich terminal text editor that is a fork of the classic Vim editor. The scope of customizing the workflow with Neovim is limitless. Neovim allows you to customize key bindings to boost your productivity. However, mastering the key bindings for different groups can be challenging, especially for beginners. Thanks to Which Key, not only can you set up custom key bindings, but it also provides a dynamic floating dashboard to remind you of your key bindings, so you never forget them again.
In this blog post, I’ll show you how to install Which Key and set up your custom key bindings. I’ll also demonstrate how to customize Which Key for the best possible experience.
You are viewing: Which Key Nvim
Prerequisites
Before proceeding with the installation and usage of Nvim Tree in Neovim, make sure you have the following packages installed on your system:
Neovim
Which Key is a plugin for Neovim that allows you to set up custom key bindings. Therefore, you must have Neovim installed to use Which Key. I assume that you have already installed Neovim.
Packer
Packer is a plugin manager for Neovim. You need Packer to install the Which Key plugin in Neovim. So, make sure Packer is installed in Neovim before installing Which Key on your system. If you haven’t installed Packer yet, consider installing Packer and follow the rest of the tutorial.
Installing Which Key
Before installing Which Key in Neovim, let’s take a look at the project structure. If you have followed our guide to install Packer, you should already have a similar structure. Don’t worry; you can still follow this guide even if you have a different structure. Just be careful when editing the configuration files.
~/.config/ └── nvim ├── init.lua └── lua ├── plugins.lua ├── whichkey.lua ├── ….. └── other configuration files
To install the Which Key plugin, open the plugins.lua file using the following command:
nvim ~/.config/nvim/lua/plugins.lua
If your plugins file has a different name or is located in a different directory, open the file accordingly. After opening the plugins file, add the following two lines to install Which Key:
– Install Which Key use (“folke/which-key.nvim”)
Once you’ve added these lines to the plugins.lua file, save it using the :w command to install the plugins.
Setting Keymaps
First, you need to choose a ladder key to create key combinations. To avoid duplicate key mappings, avoid using Alt, Ctrl, or Shift as the ladder key. For this tutorial, I’ve set the ladder key to <Space>. To use any key binding, you should use <ladder> + <key>. For example, you can map the :w command to <ladder> + w to save a file. After mapping it, you can use Space + w to save files.
To start creating key mappings, create a Lua configuration file for Which Key. Use the following command to create whichkey.lua
nvim ~/.config/nvim/lua/whichkey.lua
Then, add the following configuration to the file:
Credit: Neovim-from-scratch
Read more : Which Parking Lot Is Best For Sofi Stadium
After adding these configurations, save and exit the nvim editor using the :wq command.
Now, open the init.lua file with the following command:
nvim ~/.config/nvim/init.lua
Add the following line to the init.lua file to complete the installation:
require(“whichkey”)
After adding the line, save and quit the file.
Understanding the Key Maps in the Configuration File
In Which Key configuration, you can set both single key bindings and create key groups. Key groups contain multiple related keybindings. Group names are initiated with the + symbol, and you can identify group names by inspecting the name.
Single Key Mappings
Here are some examples of single key mappings:
- Telescope is a powerful fuzzy finder used to search files and strings. If you haven’t installed it, you can follow our guides to install it.
- NvimTree is a terminal file explorer for Neovim. If you haven’t installed Nvim Tree, you can follow our guides to install it.
Group Key Mappings
Which Key supports group key mappings where multiple related key combinations are stored. You can create your own keymapping group. Here are some commonly used keymap groups:
Packer:
Packer is a plugin manager that provides options to install, sync, and update plugins. It is accessible through the command, and you can map the packer command to <ladder> + p as the group key.
Git:
You can maintain your GitHub repository in Neovim. To increase your productivity, you are suggested to use the following key combinations within the <ladder> + g group key.
Language Server Protocol (LSP):
The Language Server Protocol (LSP) is an open standard protocol designed to facilitate communication between code editors or integrated development environments (IDEs) and language servers. You can create custom keymaps for LSP. Here are suggested key maps grouped under <space> + l group key
.
Telescope:
Read more : Which Of The Following Are Special Considerations Regarding Aeds
Telescope is a highly versatile fuzzy finder over lists. It is used for searching and can be combined with other modules for advanced actions. Here is a suggested keymapping for Telescope grouped under Search and can be accessed with <space> + s.
Terminal:
You can map terminal commands with Which Key. Here are suggested key maps grouped under Terminal and can be accessed with <space> + t.
Using Which Key
Which Key allows you to use key mapping without remembering them. You can access key maps with ladder keys. For this blog post, I have used the Space key as the ladder key. For example, open a file with Neovim and press the Space key, and you will see the key maps in a floating dashboard in the terminal, like this:
From the key maps list, you can select key maps to execute the associated commands. Notice the + symbol before the name of key maps, which represents the group key, and you can navigate further to the group.
For example, if I press l, which represents Language Server Protocol (LSP), another window will pop up containing the key maps associated with LSP:
You can select any command from the list, and you will never forget your key maps.
Changing the Color of the Which Key Float
As you have noticed, the default look of the floating window of Which Key is kind of ugly. You can change the default color of the floating window to make it easier on your eyes. To change the custom color, you need to define colors for the floating window in Neovim.
Open the options.lua file with Neovim:
nvim ~/.config/nvim/lua/options.lua
If the file does not exist, Neovim will create one. Add the following lines to the file to change the color:
Save and exit the file. Please make sure that you have added options.lua to init.lua. If you haven’t added it, open the init.lua file:
nvim ~/.config/nvim/init.lua
and add the following line to the file:
require(“options”)
Save and exit the file.
Now, open a file with Neovim and open Which Key with the ladder Space key. You will see the floating window like this:
Conclusion
Which Key is an excellent option for setting key maps and also allows you to see the key maps if you forget them. With Which Key, you won’t forget the key maps again. In this blog post, I have discussed installing and setting up the key maps for Which Key and changing the user interface.
Source: https://t-tees.com
Category: WHICH