How do I control how long Vim waits for the next key in a multi-key mapping?
Answer
:set timeoutlen={ms}
Explanation
When you press a key that starts a multi-key mapping (e.g., <leader> followed by another key), Vim waits timeoutlen milliseconds for the next keystroke before giving up and interpreting the keys individually. Adjusting this value controls the tradeoff between responsive single keys and comfortable multi-key sequences.
The two timeout options
| Option | Default | Controls |
|---|---|---|
timeoutlen |
1000ms | Timeout for mapped key sequences |
ttimeoutlen |
-1 (uses timeoutlen) | Timeout for terminal key codes (e.g., escape sequences) |
Common configurations
Faster leader key response (500ms):
set timeoutlen=500
Instant Escape key in terminal Vim (no delay leaving Insert mode):
set ttimeoutlen=10
Both together (recommended):
set timeoutlen=500
set ttimeoutlen=10
Why ttimeoutlen matters
In terminal Vim, pressing <Esc> sends the same byte as the start of escape sequences like <A-j> or arrow keys. ttimeoutlen controls how long Vim waits to see if more bytes follow. Setting it low (5–50ms) makes Escape feel instant while still allowing key codes to arrive.
Tips
- If your
<leader>mappings feel sluggish, lowertimeoutlen(try 300–500) - If multi-key mappings time out before you finish typing, raise it
ttimeoutlen=0makes Escape instant but may break Alt-key combos and arrow keys in some terminals:set timeout/:set notimeoutenables/disables mapping timeout entirely (not recommended — mappings will wait forever)- GVim does not need
ttimeoutlentuning since it handles key events directly