Chapter 17.Table of ContentsCheatsheet

Moving Even Faster with Vim Surround and EasyMotion

Vim-sneak and vim-EasyMotion are a couple of Vim plugins that supercharge how fast you can move in Vim.

Vim-sneak

Vim-sneak is a middle ground between character search (inside a line) and pattern search (inside a file):

  • Type s{char}{char} and the cursor flies to the first occurrence of that two character sequence.
  • From then on type ; for the next occurrence, or , for the previous one.
  • S{char}{char} works in a similar fashion but backwards.

Where vim-surround extended Vim’s secret language with an operator, vim-sneak does the same but with a motion: the sneak motion. As such, you can use it in combination with other operators:

  • Type {operator}z{char}{char} and the operator will be applied over the text traversed by the sneak motion.

Vim-EasyMotion

Vim-EasyMotion tries to simplify the use of motions in Vim by removing the need for counts. Instead of looking at a piece of code, counting in your head and using either of these combinations to perform some action:

{operator}{count}{motion}

or move around:

{count}{motion}

when you trigger an motion with EasyMotion, it labels the possible targets in the whole document with a key combination that is shown in an overlay (over the text in question). Type that key combination, and you’re teleported to that location at once.

For instance, type <leader><leader>w and EasyMotion will label the beginning of all words ahead of you like so:

Moving to the beginning of words in Easy motion

This is what happens when you trigger a motion with EasyMotion! :O

In the example of the image, typing the letter l would make your cursor jump to the FactionShipModifiers interface, while typing p would send you to the Energy property of that interface.

Or you could type <leader><leader>f' and EasyMotion will label all occurrences of the ' character in the current and subsequent lines. Pretty nifty, isn’t it?

All the motions provided by vim-EasyMotion are namespaced by <leader><leader>, and they use key bindings whose meaning is related to the core Vim motions:

command move to…
<leader><leader>w start of words
<leader><leader>b start of words backwards
<leader><leader>bdw start of words everywhere. The bd stands for bidirectional
<leader><leader>e end of words
<leader><leader>ge end of words backwards
<leader><leader>bdw end of words everywhere
<leader><leader>j beginning of lines
<leader><leader>k beginning of lines backwards
<leader><leader>f{char} find character
<leader><leader>F{char} find character backwards
<leader><leader>t{char} until character
<leader><leader>T{char} until character backwards
<leader><leader>s{char} search character everywhere

Jaime González García

Written by Jaime González García , dad, husband, software engineer, ux designer, amateur pixel artist, tinkerer and master of the arcane arts. You can also find him on Twitter jabbering about random stuff.Jaime González García