Neovim for Beginners — Key Mappings and WhichKey

Configure key mappings and the WhichKey plugin.

3 min readDec 28, 2021


Neovim for Beginners — Key Mappings and WhichKey

We are going to configure a few sensible default key mappings and set up the WhichKey plugin that displays a popup with possible key bindings of the command we type.

This article is part of the Neovim for Beginners series.

The Neovim configuration files can be found in this repository.

Key Mappings

Let’s configure a few sensible key mappings using the Neovim Lua API (:h nvim_set_keymap).

Note: Check out this article for the Lua keymap APIs (:h lua-keymap).

Create a file called keymaps.lua under theafter/plugin folder.

Remember that both .vim and .lua files are loaded automatically from the runtimepath (:h rtp, :h load-plugins). Vimscript files are sourced before Lua files.

  • In Insert and Terminal mode, we use jk to transition to the Normal mode.
  • We always center the search results when moving back and forth.
  • We map k and j to gj and gk for better lines navigation when lines wrap (:h gk, :h gj).
  • We map < and > in Visual mode for better indentation. gv automatically selects the previously selected area.
  • We use the black hole register “_ (:h registers) to prevent yanking the selected text during pasting in Visual mode.
  • We use <Shift-h> and <Shift-l> to navigate between the previous and next buffer.
  • We use <ESC> to clear the highlighted search matches.
  • We use K and J to move selected lines up and down in Visual mode.




Software engineer, Data Science and ML practitioner.