Skip to main content

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

event = "VeryLazy"
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:
KeyActionDescription
<leader>dDiagnostics menuShow diagnostic commands
Common diagnostic operations:
  • View diagnostic messages
  • Navigate between diagnostics
  • Open diagnostic float
  • Set diagnostic loclist

<leader>e - Explorer

File explorer commands:
KeyActionDescription
<leader>eExplorer menuShow explorer commands
Explorer operations:
  • Toggle file explorer
  • Focus file explorer
  • Reveal current file
  • Refresh explorer

<leader>f - Find

Telescope fuzzy finding:
KeyActionDescription
<leader>fFind menuShow 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:
KeyActionDescription
<leader>lLazy panels menuShow lazy-related commands
<leader>llLazyGitOpen LazyGit interface
Lazy operations:
  • Open Lazy.nvim UI
  • Update plugins
  • Check plugin status
  • Open LazyGit

<leader>m - Mason

Mason package manager:
KeyActionDescription
<leader>mMason menuShow Mason commands
Mason operations:
  • Open Mason UI
  • Install LSP servers
  • Update tools
  • View installed packages

<leader>n - NoHighlight

Search highlight management:
KeyActionDescription
<leader>nNoHighlight menuClear search highlighting
Operations:
  • Clear search highlights
  • Toggle highlight on/off

<leader>p - File Explorer

Another file explorer group (possibly nvim-tree specific):
KeyActionDescription
<leader>pFile Explorer menuShow file explorer commands
File explorer operations:
  • Toggle tree view
  • Find current file
  • Collapse all folders
  • Expand all folders

<leader>s - Splits

Window split management:
KeyActionDescription
<leader>sSplits menuShow split commands
Split operations:
  • Split horizontally
  • Split vertically
  • Close split
  • Resize splits
  • Navigate between splits

<leader>t - Tabs

Tab management:
KeyActionDescription
<leader>tTabs menuShow tab commands
Tab operations:
  • New tab
  • Close tab
  • Next/previous tab
  • Move tab
  • Organize tabs

<leader>w - Workspace

LSP workspace commands:
KeyActionDescription
<leader>wWorkspace menuShow workspace commands
Workspace operations:
  • Add workspace folder
  • Remove workspace folder
  • List workspace folders
  • Workspace symbols

<leader>x - Trouble

Trouble diagnostics panel:
KeyActionDescription
<leader>xTrouble menuShow Trouble commands
Trouble operations:
  • Open diagnostics
  • Open quickfix
  • Open loclist
  • Toggle Trouble panel

Usage

Discovering Keybindings

  1. Press leader key: Type <leader> (usually space)
  2. Wait 500ms: Which-key popup appears automatically
  3. View options: See all available keybinding groups
  4. Navigate: Press a letter to see that group’s commands
  5. Execute: Complete the key sequence to run a command

Example Workflow

Finding Files

  1. Press <space> (leader key)
  2. Popup shows: f → Find, e → Explorer, etc.
  3. Press f to see find commands
  4. Popup shows file-finding options
  5. Press the key for your desired find operation

Opening LazyGit

  1. Press <space> (leader key)
  2. Popup shows groups including l → Lazy panels
  3. Press l
  4. Popup shows lazy-related commands including l → LazyGit
  5. Press l again to open LazyGit
Full sequence: <leader>ll

Speedy Execution

If you know the keybinding:
  1. Type the full sequence quickly (within 500ms)
  2. Command executes without popup appearing
  3. 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.

Custom Popup Layout

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:
  1. Press <leader> and wait
  2. Read the popup to see what’s available
  3. Explore each group by pressing the corresponding key
  4. Use <esc> to go back or cancel

Speed Up Your Workflow

Once you know the keybindings:
  1. Type sequences quickly without waiting for popup
  2. Common sequences become muscle memory
  3. Still see popup when you forget (after 500ms)

Viewing All Keybindings

To see ALL keybindings in Neovim:
:WhichKey
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:
  1. Open Neovim
  2. Run :WhichKey
  3. Take a screenshot or copy the display
  4. 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>gb/c/d for branches/commits/diff.

Troubleshooting

If which-key popup doesn’t show:
  1. Check timeout is enabled:
    :set timeout?
    
    Should return timeout
  2. Check timeout length:
    :set timeoutlen?
    
    Should return timeoutlen=500
  3. Verify plugin is loaded:
    :Lazy
    
    Look for which-key.nvim
  4. Reload plugin:
    :Lazy reload which-key.nvim
    

Keybindings Not Listed

If a keybinding doesn’t appear in which-key:
  1. Check if description is provided:
    vim.keymap.set("n", "<leader>x", cmd, {
      desc = "Description here",  -- Required for which-key
    })
    
  2. Verify the group is registered: Check lua/magictt/plugins/which-key.lua:11-23 for the group
  3. Check keybinding was set:
    :map <leader>x
    

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:
  1. Add group definitions in which-key config
  2. Ensure group name matches keybinding prefix
  3. Reload Neovim

External Resources

Build docs developers (and LLMs) love