Step 2 of 7

8. Searching

Jumping between matches

Once you’ve made a search, you can jump between matches with the n and N keys.

  • n jumps to the next match in the direction that you initiated the search — so if you initiated the search with /, n jumps forward in the document, but if you initiated with ?, n jumps backwards.
  • N jumps to the next match in the opposite direction to what you initiated the search with.

Searches in Vim wrap around by default, so if you’re on the last match in the document and you hit n, you’ll be taken to the first match.

Work through the checklist below. This time, there are a few NEEDLE lines among the HAYSTACK lines — start searching for NEEDLE, then use n and N to jump between the matches and wrap back around to where you started.

  1. Search for the needles You'll land on the first of four NEEDLE lines — type /NEEDLE and hit Enter.
  2. Jump to the next match The second needle is a few thousand lines further down — press n.
  3. Jump back to the previous match You'll hop back up to the first needle — press N.
  4. Wrap around the document Two more needles wait below; the stop is back at the first one — keep pressing n until the search wraps around.
Search for the needles You'll land on the first of four NEEDLE lines — type /NEEDLE and hit Enter.

Next: Jump to the next match

Loading editor…