vimtricks.wiki Concise Vim tricks, one at a time.

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 characters
  • S{char}{char} — jump backward
  • ; — repeat the sneak forward (next match)
  • , — repeat the sneak backward (previous match)
  • Works across lines (unlike f/t which 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 next ab
  • czab — change from cursor to the next ab
  • yzab — yank from cursor to the next ab

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) — use cl instead, or remap sneak to a different key
  • Two characters gives much better targeting than one: sth almost always lands you exactly where you want
  • Sneak respects ignorecase and smartcase settings
  • For even faster navigation, enable label mode — it turns sneak into a lightweight EasyMotion

Next

How do I run a search and replace only within a visually selected region?