Skip to content
Dimitri Sabadie edited this page Jul 5, 2022 · 4 revisions

Hop commands

Hop ships with a lot of Neovim commands already configured for you to use. Commands start with Hop and can have variations. It is important to understand that not everything Hop can do is exposed via commands: only the mostly used commands have an exported Neovim command. Some features might require you to go through the Lua API instead.

To invoke a Hop command, you need to press the : key, type the Hop command, and then press RET to execute the command. For instance, to hop to words in the current buffer:

:HopWord

Command variations

Hop commands can have variations. A variation is more restricted or more general version of the command without the variation. For instance, the HopWord command can have variations allowing to run that command across all visible buffers (and not only the current one) or on the portion of text before the cursor.

Not all commands will have the same variations, and not all features of Hop are representable via variations. If you do not find what you want in a command variations, it’s likely that the Lua API can still do it.

There are four command variations, with some of them that can be combined:

  • Hop*BC: run Hop* before the cursor.
  • Hop*AC: run Hop* after the cursor.
  • Hop*CurrentLine: run Hop* on the current line only.
  • Hop*MW: run Hop* across all visible buffers.

You will also find combinations, like:

  • Hop*CurrentLineBC: run Hop* both before the cursor and on the current line only.
  • Hop*CurrentLineAC: run Hop* both after the cursor and on the current line only.

Command list

As explain in the Command variations section, some commands have variations. Because they all do the same thing, the list of commands here does not include the variation commands (you can deduce what they do by reading the variation section). The total list of commands is then much higher than the list presented here. You get the idea.

HopAnywhere

The most powerful command and yet probably the less useful, this command will hint everything in the buffer and will allow you to jump to them. Because a lot of items will be hinted, that command will most of the time require you to type several keys before triggering a jump, making that command not so useful to use.

HopChar1

This command prompts you to type one key, and will hint that key in the buffer. This is a very useful command to have mapped to a quick key as it will allow you to jump to special characters, such as characters not part of keywords or words, like punctuation, operators, etc. etc.

Step 1: press a key.

hop_char1_step1

Step 2: press the key sequence to jump to the hint (here, we pressed the . key).

hop_char1_step2

HopChar2

Prompts you for two keys to type and hint the bigram in the buffer. This is also very useful as most of the place you want to jump will be quickly identified by only two keys.

Bonus: if you change your mind and decide to type only one key, you don’t have to abort (with ESC) and use HopChar1: instead, just press RET, which will immediately hint the only key you have pressed, yielding the same behavior as of HopChar1.

Step 1: press a key.

Step 2: either press another key, or RET to fallback to HopChar1.

hop_char2_step1

Step 3: press the key sequence to jump to the hint (here, we pressed the lo key sequence).

hop_char2_step2

HopLine

A pretty useful command, it will hint the first column of each visible line.

hop_line_step1

HopLineStart

Similar to HopLine, the only difference is that it will hint the first non-whitespace character of each line (similar to the _ motion).

hop_line_start_step1

HopVertical

Very similar to HopLine and HopLineStart, the only difference is that HopVertical will try to keep the cursor column position as the same as your current cursor.

If a line is shorter than your cursor column position, its end of line will be used as jump target.

hop_vertical_step1

HopPattern

A powerful command that mixes the default Neovim search (/) with hinting. This command will prompt you with any kind of pattern, that you can validate with RET.

Step 1: enter a pattern and press RET to validate it.

hop_pattern_step1

Step 2: press the key sequence to jump to the hint (here, we typed local as pattern).

hop_pattern_step2

HopWord

Probably the most useful command of all, it will hint all words in your buffer. It is really simple and most of the time will bring your cursor so close to the position you actually want to go to that most of the time, it is easier to jump close to the position rather than the exact position.

hop_word_step1