How do I jump to any visible location with a two-character search using vim-sneak?
Answer
s{char}{char}
Explanation
vim-sneak (by Justin M. Keyes) adds a motion that jumps to the next occurrence of a two-character sequence. Press s followed by two characters, and the cursor lands on the first match. Press s or ; again to cycle to the next match. It fills the gap between f (single character, current line only) and / (full regex, requires <CR>).
How it works
s{char}{char}— jump forward to the next occurrence of the two charactersS{char}{char}— jump backward;— repeat the sneak forward (next match),— repeat the sneak backward (previous match)- Works across lines (unlike
f/twhich are line-local)
Install with: Plug 'justinmk/vim-sneak'
Example
To jump to the word function from anywhere above it:
sfu
The cursor lands on the f of the next fu sequence. Press ; to cycle to the next fu if that was not the right one.
As an operator
Sneak works with operators:
dzab— delete from cursor to the nextabczab— change from cursor to the nextabyzab— yank from cursor to the nextab
Label mode (optional)
Enable label mode for EasyMotion-like behavior:
let g:sneak#label = 1
All matches get a label character — press it to jump directly, no cycling needed.
Tips
- Sneak replaces
s(substitute) — useclinstead, or remap sneak to a different key - Two characters gives much better targeting than one:
sthalmost always lands you exactly where you want - Sneak respects
ignorecaseandsmartcasesettings - For even faster navigation, enable label mode — it turns sneak into a lightweight EasyMotion