Step 7 of 8

14. Marks

Special marks: visual selection

We’ve already met the gv command, which allows us to reselect our previous visual selection. When we use gv, how does Vim know where the last visual selection was?

The answer is that Vim sets the '< and '> marks to remember the last visual selection. This is useful to know — it means we can jump to the start of the last visual selection with '<, and the end with '>.

Work through the checklist below. Select the paragraph in the editor, drop back to normal mode, then use '< and '> to hop to the start and end of the selection you made.

  1. Select the paragraph with vip Put your cursor anywhere inside the paragraph and type vip.
  2. Back out to normal mode The highlight will disappear, but Vim remembers where it was — press Escape. (Deleted the text by accident? u undoes it.)
  3. Jump to the start of the selection with '< The first line of the paragraph you selected — press '<.
  4. Jump to the end with '> And the last line — press '>.
Select the paragraph with vip Put your cursor anywhere inside the paragraph and type vip.

Next: Back out to normal mode

Loading editor…