Which Key Nvim

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.

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.

Refer to more articles:  Which Of The Three Suspects Genshin

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”)

Installing Which Key

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

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.

Refer to more articles:  Which Is The Best Lightweight Folding Mobility Scooter

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:

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:

Refer to more articles:  Which Of These Statements About Smart Shopping Campaigns Is Accurate
Which Key UI

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:

Which Key UI

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:

Modified Which Key UI

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.

Related Posts

Which Is Not A Function Of Epithelial Tissue

What is the epithelium? The epithelium is a type of body tissue that forms the covering on all internal and external surfaces of your body, lines body…

Which Animal Has The Best Memory

Memory is the brain’s ability to encode and recall the needed information. In other words, memory – the capacity, which enables the remembrance of events, thought, feeling,…

Which Of The Following Genotypes Is Homozygous

What is homozygous? In genetics, the definition of homozygous is when you inherit the same DNA sequence for a specific gene from each of your biological parents….

Which Lines Are Parallel Check All That Apply

Which Lines Are Parallel Check All That Apply

Parallel lines are the lines that do not intersect or meet each other at any point in a plane. They are always parallel and are at equidistant…

Which Of The Following Is True Of Bloodborne Pathogens

Under OSHA’s Bloodborne Pathogens Standard requirements, all employees are to be regularly trained on the risks of occupational exposure to infectious materials. Workers should have a deep…

Which Leg Wear Anklet

Anklets are the perfect accessory for people who don’t like large flash jewelry.You may be interested Which Of The Following Is A Symptom Which Aaa Component Can…