Overview
Which-key is a Neovim plugin that displays available keybindings in a popup window as you type. The Magictt config uses which-key to organize keybindings into logical groups, making it easy to discover and remember keyboard shortcuts.
What Which-key Does
- Keybinding Discovery: Shows available keybindings as you type
- Visual Organization: Groups related commands under common prefixes
- Interactive Help: Provides descriptions for each keybinding
- Timeout Management: Configurable delay before popup appears
- Learning Aid: Helps you learn and remember complex keybindings
Configuration
The which-key configuration from the source:
return {
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 500
end,
opts = {},
config = function()
local wk = require("which-key")
wk.add({
{ "<leader>d", group = "Diagnostics" },
{ "<leader>e", group = "Explorer" },
{ "<leader>f", group = "Find" },
{ "<leader>l", group = "Lazy panels" },
{ "<leader>m", group = "Mason" },
{ "<leader>n", group = "NoHighlight" },
{ "<leader>p", group = "File Explorer" },
{ "<leader>s", group = "Splits" },
{ "<leader>t", group = "Tabs" },
{ "<leader>w", group = "Workspace" },
{ "<leader>x", group = "Trouble" },
})
end,
}
Source: lua/magictt/plugins/which-key.lua:1-26
Configuration Details
Lazy Loading
Which-key loads after Neovim startup is complete:
- Doesn’t slow down initial startup
- Loads before you need it
- Available almost immediately
Timeout Settings
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 500
end
- timeout: Enables timeout for key sequences
- timeoutlen: 500ms delay before which-key popup appears
The 500ms timeout means you have half a second to continue typing before the popup shows. This balances discoverability with speed for experienced users.
Keybinding Groups
Which-key organizes keybindings into these groups:
wk.add({
{ "<leader>d", group = "Diagnostics" },
{ "<leader>e", group = "Explorer" },
{ "<leader>f", group = "Find" },
{ "<leader>l", group = "Lazy panels" },
{ "<leader>m", group = "Mason" },
{ "<leader>n", group = "NoHighlight" },
{ "<leader>p", group = "File Explorer" },
{ "<leader>s", group = "Splits" },
{ "<leader>t", group = "Tabs" },
{ "<leader>w", group = "Workspace" },
{ "<leader>x", group = "Trouble" },
})
Source: lua/magictt/plugins/which-key.lua:11-23
Keybinding Groups Reference
<leader>d - Diagnostics
LSP diagnostic commands:
| Key | Action | Description |
|---|
<leader>d | Diagnostics menu | Show diagnostic commands |
Common diagnostic operations:
- View diagnostic messages
- Navigate between diagnostics
- Open diagnostic float
- Set diagnostic loclist
<leader>e - Explorer
File explorer commands:
| Key | Action | Description |
|---|
<leader>e | Explorer menu | Show explorer commands |
Explorer operations:
- Toggle file explorer
- Focus file explorer
- Reveal current file
- Refresh explorer
<leader>f - Find
Telescope fuzzy finding:
| Key | Action | Description |
|---|
<leader>f | Find menu | Show find commands |
Typical find operations:
- Find files
- Find in files (grep)
- Find buffers
- Find help tags
- Find recent files
- Find git files
<leader>l - Lazy Panels
Lazy.nvim plugin manager and related:
| Key | Action | Description |
|---|
<leader>l | Lazy panels menu | Show lazy-related commands |
<leader>ll | LazyGit | Open LazyGit interface |
Lazy operations:
- Open Lazy.nvim UI
- Update plugins
- Check plugin status
- Open LazyGit
<leader>m - Mason
Mason package manager:
| Key | Action | Description |
|---|
<leader>m | Mason menu | Show Mason commands |
Mason operations:
- Open Mason UI
- Install LSP servers
- Update tools
- View installed packages
<leader>n - NoHighlight
Search highlight management:
| Key | Action | Description |
|---|
<leader>n | NoHighlight menu | Clear search highlighting |
Operations:
- Clear search highlights
- Toggle highlight on/off
<leader>p - File Explorer
Another file explorer group (possibly nvim-tree specific):
| Key | Action | Description |
|---|
<leader>p | File Explorer menu | Show file explorer commands |
File explorer operations:
- Toggle tree view
- Find current file
- Collapse all folders
- Expand all folders
<leader>s - Splits
Window split management:
| Key | Action | Description |
|---|
<leader>s | Splits menu | Show split commands |
Split operations:
- Split horizontally
- Split vertically
- Close split
- Resize splits
- Navigate between splits
<leader>t - Tabs
Tab management:
| Key | Action | Description |
|---|
<leader>t | Tabs menu | Show tab commands |
Tab operations:
- New tab
- Close tab
- Next/previous tab
- Move tab
- Organize tabs
<leader>w - Workspace
LSP workspace commands:
| Key | Action | Description |
|---|
<leader>w | Workspace menu | Show workspace commands |
Workspace operations:
- Add workspace folder
- Remove workspace folder
- List workspace folders
- Workspace symbols
<leader>x - Trouble
Trouble diagnostics panel:
| Key | Action | Description |
|---|
<leader>x | Trouble menu | Show Trouble commands |
Trouble operations:
- Open diagnostics
- Open quickfix
- Open loclist
- Toggle Trouble panel
Usage
Discovering Keybindings
- Press leader key: Type
<leader> (usually space)
- Wait 500ms: Which-key popup appears automatically
- View options: See all available keybinding groups
- Navigate: Press a letter to see that group’s commands
- Execute: Complete the key sequence to run a command
Example Workflow
Finding Files
- Press
<space> (leader key)
- Popup shows:
f → Find, e → Explorer, etc.
- Press
f to see find commands
- Popup shows file-finding options
- Press the key for your desired find operation
Opening LazyGit
- Press
<space> (leader key)
- Popup shows groups including
l → Lazy panels
- Press
l
- Popup shows lazy-related commands including
l → LazyGit
- Press
l again to open LazyGit
Full sequence: <leader>ll
Speedy Execution
If you know the keybinding:
- Type the full sequence quickly (within 500ms)
- Command executes without popup appearing
- Example:
<space>ff (fast) opens file finder immediately
Customization
Changing Timeout Duration
To adjust how long before the popup appears, edit lua/magictt/plugins/which-key.lua:6:
vim.o.timeoutlen = 300 -- Changed from 500 (faster popup)
-- or
vim.o.timeoutlen = 1000 -- Changed from 500 (slower popup)
- Lower value (e.g., 300): Popup appears faster (good for learning)
- Higher value (e.g., 1000): More time to type sequences (good for speed)
Adding New Groups
To add a new keybinding group, edit lua/magictt/plugins/which-key.lua:11-23:
wk.add({
{ "<leader>d", group = "Diagnostics" },
{ "<leader>e", group = "Explorer" },
-- ... existing groups ...
{ "<leader>g", group = "Git" }, -- New group
{ "<leader>r", group = "Refactor" }, -- New group
})
Adding Keybinding Descriptions
When defining keybindings in other plugins, add descriptions:
vim.keymap.set("n", "<leader>ff", telescope.find_files, {
desc = "Find files", -- Shows in which-key popup
})
The desc field appears in the which-key popup automatically.
To customize the popup appearance:
opts = {
window = {
border = "double", -- Border style
position = "bottom", -- Position on screen
margin = { 1, 0, 1, 0 }, -- Margins
padding = { 1, 2, 1, 2 }, -- Padding
},
layout = {
height = { min = 4, max = 25 },
width = { min = 20, max = 50 },
spacing = 3,
},
}
Disable for Specific Keys
To disable which-key for certain key sequences:
opts = {
plugins = {
marks = false, -- Disable for marks
registers = false, -- Disable for registers
spelling = {
enabled = false, -- Disable for spelling suggestions
},
},
}
Tips and Tricks
Learning Keybindings
When learning the config:
- Press
<leader> and wait
- Read the popup to see what’s available
- Explore each group by pressing the corresponding key
- Use
<esc> to go back or cancel
Speed Up Your Workflow
Once you know the keybindings:
- Type sequences quickly without waiting for popup
- Common sequences become muscle memory
- Still see popup when you forget (after 500ms)
Viewing All Keybindings
To see ALL keybindings in Neovim:
This shows keybindings for the current mode.
For specific modes:
:WhichKey <leader> n " Normal mode, leader key
:WhichKey <leader> v " Visual mode, leader key
:WhichKey '' i " Insert mode, all keys
Creating a Reference Sheet
To print/export all keybindings:
- Open Neovim
- Run
:WhichKey
- Take a screenshot or copy the display
- Create a cheat sheet for reference
Mode-Specific Groups
Add groups for different modes:
wk.add({
-- Normal mode (default)
{ "<leader>f", group = "Find" },
-- Visual mode
{ "<leader>g", group = "Git", mode = "v" },
})
Nested Groups
Create hierarchical keybinding structures:
wk.add({
{ "<leader>g", group = "Git" },
{ "<leader>gb", group = "Branches" },
{ "<leader>gc", group = "Commits" },
{ "<leader>gd", group = "Diff" },
})
This creates <leader>g → b/c/d for branches/commits/diff.
Troubleshooting
If which-key popup doesn’t show:
-
Check timeout is enabled:
Should return
timeout
-
Check timeout length:
Should return
timeoutlen=500
-
Verify plugin is loaded:
Look for which-key.nvim
-
Reload plugin:
:Lazy reload which-key.nvim
Keybindings Not Listed
If a keybinding doesn’t appear in which-key:
-
Check if description is provided:
vim.keymap.set("n", "<leader>x", cmd, {
desc = "Description here", -- Required for which-key
})
-
Verify the group is registered:
Check
lua/magictt/plugins/which-key.lua:11-23 for the group
-
Check keybinding was set:
Timeout Too Fast/Slow
Adjust the timeout in lua/magictt/plugins/which-key.lua:6:
- Too fast (popup appears too soon): Increase timeoutlen
- Too slow (waiting too long): Decrease timeoutlen
Groups Not Organized
If keybindings appear but aren’t grouped:
- Add group definitions in which-key config
- Ensure group name matches keybinding prefix
- Reload Neovim
External Resources