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

How do I quickly jump to any location with two characters?

Answer

s{char}{char} (vim-sneak)

Explanation

vim-sneak provides a motion that lets you jump to any location specified by two characters. It is faster than f because it works across lines.

How it works

  • s{char}{char} jumps forward to the next occurrence of those two characters
  • S{char}{char} jumps backward
  • ; and , repeat the motion forward and backward

Example

To jump to the word function from anywhere visible, type sfu — this jumps to the first fu in the buffer.

Tips

  • Install: Plug 'justinmk/vim-sneak'
  • More precise than f because two chars narrow the matches significantly
  • s replaces the built-in s command (use cl instead)
  • Can be configured to highlight all matches like EasyMotion
  • Works as a motion with operators: dsab deletes to the next ab

Next

How do you yank a single word into a named register?