lua/user/keymaps.lua for general keybindings and lua/user/whichkey.lua for leader-based keymaps with visual feedback.
Understanding the Keymap System
Leader Key
The leader key is set to<Space> (spacebar):
Vim Modes
Keymaps can be set for different modes:n- Normal modei- Insert modev- Visual modex- Visual block modet- Terminal modec- Command mode""- All modes
Adding Basic Keymaps
The keymap Function
Keymaps are created usingvim.keymap.set:
Keymap Options
Examples from the Codebase
Window Navigation
Navigate between splits usingCtrl+h/j/k/l:
Window Resizing
Resize windows with arrow keys:Buffer Navigation
Switch between buffers usingShift+h/l:
Moving Text
Move lines up and down withAlt+j/k:
Quick Insert Mode Exit
Exit insert mode by pressingjk or kj:
Visual Mode Indentation
Stay in indent mode after indenting:Better Paste
Paste over text without yanking the replaced text:Adding Leader-Based Keymaps
Leader keymaps are defined inlua/user/whichkey.lua and provide visual feedback through the which-key plugin.
Which-Key Structure
<leader>a- Open Alpha dashboard<leader>e- Toggle file explorer<leader>w- Save file<leader>q- Quit Neovim
Grouped Keymaps
Create submenu groups for related commands:<leader>gg- Open Lazygit<leader>gj- Next git hunk<leader>gk- Previous git hunk<leader>gl- Git blame line<leader>gp- Preview git hunk
Telescope Integration
Keymaps for fuzzy finding:LSP Keymaps
Language server protocol commands:Adding Your Own Keymaps
Method 1: Simple Keymaps in keymaps.lua
For mode-specific keymaps without leader key: Editlua/user/keymaps.lua:
Method 2: Leader Keymaps in whichkey.lua
For leader-based keymaps with documentation: Editlua/user/whichkey.lua mappings table:
Practical Examples
Example 1: Quick File Operations
Example 2: Terminal Integration
Example 3: Custom Lua Function
Create a keymap that runs a custom Lua function: Step 1: Define your function inlua/user/functions.lua:
lua/user/whichkey.lua:
Viewing Current Keymaps
Using Which-Key
Press<leader> and wait - which-key will show all available leader keymaps.
Using Telescope
Search all keymaps:Using Vim Commands
Keymap Best Practices
- Use mnemonic leaders -
gfor git,lfor LSP,ffor find - Document your keymaps - Use which-key for self-documentation
- Avoid conflicts - Check existing keymaps before adding new ones
- Group related commands - Use which-key groups for organization
- Use silent option - Prevent command display in command line
- Test thoroughly - Ensure keymaps work in the intended mode
Special Key Notations
<CR>- Enter/Return<Space>- Space bar<BS>- Backspace<Tab>- Tab key<S-...>- Shift + key<C-...>- Control + key<A-...>or<M-...>- Alt/Meta + key<leader>- Leader key (Space)<cmd>...<cr>- Execute command
Troubleshooting
Keymap Not Working
- Check mode is correct (normal, insert, visual)
- Verify no conflicting mappings
- Test command manually first
- Check plugin is loaded (for plugin commands)
Which-Key Not Showing
- Ensure which-key plugin is installed
- Check
lua/user/whichkey.luais loaded - Verify mapping is in the
mappingstable - Run
:WhichKeymanually to test

