Vim Tips and Tricks
A few essential tips to improve your Vim speed and comfort. The most important is remapping Caps Lock to Escape, which makes switching modes much more ergonomic.
Remap Caps Lock to Escape
The Esc
key is vital for switching to Normal mode, but it's awkwardly placed. Remapping the Caps Lock
key is a common and highly recommended optimization.
On Windows
Method 1: Registry File
- Save the following as a
.reg
file (e.g.,remap.reg
):regWindows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
- Double-click the file to apply it.
- Reboot your computer.
Method 2: PowerToys
Use the Keyboard Manager utility in Microsoft PowerToys for a graphical way to remap keys.
On macOS
- Open System Settings > Keyboard.
- Click Keyboard Shortcuts... > Modifier Keys.
- Change the "Caps Lock Key" to Escape.
Speed Up Key Repeat
Faster key repeat makes navigating with h
, j
, k
, l
much quicker.
- Windows: Go to Control Panel > Keyboard and adjust the "Repeat rate" and "Repeat delay".
- macOS: Go to System Settings > Keyboard and adjust "Key repeat rate" and "Delay until repeat".
Use the Dot .
Command
The dot (.
) command repeats your last change (e.g., an insertion, deletion, or modification). After changing a word with cw
, you can move to another word and press .
to apply the same change instantly.
Combine Operators and Motions
Vim's grammar is operator
+ motion
. This is a core concept.
- Operators:
d
(delete),c
(change),y
(yank/copy). - Motions:
w
(word),$
(end of line),G
(end of file).
Examples:
dw
: Delete word.d$
: Delete to the end of the line.cG
: Change from the cursor to the end of the file.y/foo
: Yank everything until the word "foo".