lua/user/keymaps.lua file defines custom key bindings that enhance navigation, editing, and window management in Neovim.
Overview
Keymaps are configured usingvim.keymap.set with options for different modes (normal, insert, visual, etc.). The space key is set as the leader key for custom commands.
Leader Key Configuration
lua/user/keymaps.lua
Keymap Options
- noremap: Prevents recursive mapping
- silent: Suppresses command output in the command line
Mode Reference
Keymaps are mode-specific. Understanding Neovim modes is essential for effective key binding configuration.
| Mode | Code | Description |
|---|---|---|
| Normal | n | Default mode for navigation and commands |
| Insert | i | Text insertion mode |
| Visual | v | Visual selection mode |
| Visual Block | x | Visual block selection mode |
| Terminal | t | Terminal emulator mode |
| Command | c | Command-line mode |
Normal Mode Keymaps
Window Navigation
| Keybinding | Action | Description |
|---|---|---|
Ctrl-h | <C-w>h | Move to left window |
Ctrl-j | <C-w>j | Move to window below |
Ctrl-k | <C-w>k | Move to window above |
Ctrl-l | <C-w>l | Move to right window |
Window Resizing
Arrow Key Resizing
Arrow Key Resizing
Use Ctrl + Arrow keys to resize split windows:
| Keybinding | Action | Description |
|---|---|---|
Ctrl-Up | :resize -2 | Decrease window height |
Ctrl-Down | :resize +2 | Increase window height |
Ctrl-Left | :vertical resize -2 | Decrease window width |
Ctrl-Right | :vertical resize +2 | Increase window width |
Buffer Navigation
Next Buffer
Shift-l: Switch to next buffer
Previous Buffer
Shift-h: Switch to previous buffer
Moving Lines
Quickly move lines up or down while maintaining indentation:| Keybinding | Action | Description |
|---|---|---|
Alt-j | :m .+1<CR>== | Move current line down |
Alt-k | :m .-2<CR>== | Move current line up |
Insert Mode Keymaps
Quick Exit
| Keybinding | Action | Description |
|---|---|---|
jk | <ESC> | Exit insert mode |
kj | <ESC> | Exit insert mode |
Visual Mode Keymaps
Indentation
| Keybinding | Action | Description |
|---|---|---|
< | <gv^ | Decrease indentation and reselect |
> | >gv^ | Increase indentation and reselect |
Moving Text
Move selected text up or down:| Keybinding | Action | Description |
|---|---|---|
Alt-j | :m '>+1<CR>gv=gv | Move selection down |
Alt-k | :m '<-2<CR>gv=gv | Move selection up |
Paste Behavior
Visual Block Mode Keymaps
Visual block mode allows you to select rectangular blocks of text:| Keybinding | Action | Description |
|---|---|---|
J | :m '>+1<CR>gv=gv | Move block down |
K | :m '<-2<CR>gv=gv | Move block up |
Alt-j | :m '>+1<CR>gv=gv | Move block down |
Alt-k | :m '<-2<CR>gv=gv | Move block up |
Terminal Mode Keymaps
Terminal navigation keymaps are currently commented out but available if needed.
Adding Custom Keymaps
Determine the mode
Decide which mode(s) the keybinding should work in (normal, insert, visual, etc.).
Keymap Examples
Best Practices
Use Leader Key
Prefix custom commands with
<leader> to avoid conflicts with built-in mappings.Be Consistent
Group related commands with similar prefixes (e.g.,
<leader>f for file operations).Document Mappings
Add comments explaining what complex keybindings do.
Test Carefully
Ensure new mappings don’t override important default behavior.
See Also
Options
Configure editor behavior and settings
Plugins
Plugin-specific keybindings

