How do I display available keybindings in a popup when pressing leader?
Answer
:WhichKey
Explanation
which-key.nvim shows a popup window with available keybindings after you press a prefix key like <leader>. This eliminates the need to memorize every mapping — just press the prefix and the popup guides you through available options.
How it works
- Press
<leader>— after a short delay, a popup shows all<leader>mappings - Navigate nested groups by pressing the next key
- Mappings are automatically discovered from your configuration
- Custom labels can describe what each key does
Example
require('which-key').setup()
require('which-key').register({
['<leader>f'] = { name = '+find' },
['<leader>ff'] = { ':Telescope find_files<CR>', 'Find Files' },
['<leader>fg'] = { ':Telescope live_grep<CR>', 'Live Grep' },
['<leader>g'] = { name = '+git' },
['<leader>gs'] = { ':Git<CR>', 'Git Status' },
})
After pressing <leader>:
┌─────────────────────────┐
│ f → +find │
│ g → +git │
│ b → +buffers │
│ w → Save file │
└─────────────────────────┘
Tips
- Works with any prefix, not just
<leader>:g,z,],[, etc. - Groups create hierarchical menus:
<leader>f→ submenu of find commands - Automatically detects existing mappings — no configuration needed for basic use
- Set
timeoutlen=300for a quicker popup appearance