lua/magictt/core/keymaps.lua, while plugin-specific keymaps are defined in their respective plugin files.
Where to Add Keymaps
Core Keymaps
General-purpose keymaps go inlua/magictt/core/keymaps.lua.
Plugin-Specific Keymaps
Plugin keymaps should be defined in the plugin’s config function (e.g.,lua/magictt/plugins/telescope.lua:30-36).
Keymap Syntax
The basic syntax for creating a keymap:Parameters
mode- The mode(s) where the keymap applies:"n"- Normal mode"i"- Insert mode"v"- Visual mode"x"- Visual block mode"t"- Terminal mode"c"- Command mode
keys- The key combination to trigger the commandcommand- The command to execute (string or function)options- Optional table with:desc- Description (shown in which-key)silent- Don’t show command in command linenoremap- Don’t allow remappingbuffer- Apply to current buffer only
Real Examples from Magictt
Leader Key (keymaps.lua:1-2)
The leader key is set to space:Exit Insert Mode (keymaps.lua:6)
jk quickly in insert mode to return to normal mode.
File Explorer (keymaps.lua:7)
<space>pv in normal mode to open the file explorer.
Clear Search Highlights (keymaps.lua:12)
Window Management (keymaps.lua:22-25)
Tab Management (keymaps.lua:27-31)
Number Increment/Decrement (keymaps.lua:16-17)
Adding Your Own Keymaps
Best Practices
1. Use Descriptive Names
Always include adesc option so the keymap appears in which-key:
2. Group Related Keymaps
Use consistent prefixes for related functions:<leader>f- Find/search operations (Telescope)<leader>s- Split window operations<leader>t- Tab operations<leader>m- Misc operations (Mason, etc.)
3. Avoid Conflicts
Check existing keymaps before adding new ones:<leader> and browsing.
4. Use Leader Key for Custom Commands
The leader key (<space>) is reserved for user-defined keymaps. Avoid overriding default Vim keymaps unless intentional.
5. Make It Memorable
Choose intuitive key combinations:<leader>ff- Find Files<leader>fs- Find String<leader>sv- Split Vertically<leader>sh- Split Horizontally
Advanced Patterns
Function Keymaps
Execute a Lua function:Buffer-Specific Keymaps
Keymaps that only apply to the current buffer:Multiple Modes
Apply the same keymap to multiple modes:Conditional Keymaps
Create keymaps based on conditions:Plugin-Specific Keymaps
When adding a plugin, define its keymaps in the plugin file’s config function:Common Key Notations
<CR>- Enter<ESC>- Escape<C-x>- Ctrl + x<S-x>- Shift + x<A-x>or<M-x>- Alt + x<leader>- Space (in Magictt)<cmd>- Execute command mode command
Viewing All Keymaps
To see all keymaps:<leader> and browsing available keymaps.