Step 6 of 6

18. Ex Commands Addresses And Ranges

Visual mode and the range operator

By now, we’ve probably seen this thing a few times: '<,'>

What does that mean?!

We can decipher that now. First, understand that Vim uses the < and > marks to represent the start and end of a visual selection respectively. If you highlight a range of lines, the < mark will be placed at the start of your visual selection and the > mark the end.

Now recall that 't is an address specifier that specifies the line of mark t.

Putting these two facts together, we understand that '<,'> is a range that represents the current (or previous) visual selection! That’s why, if you’re in visual mode and you type :, Vim will pre-populate the command line with '<,'>. It’s because most of the time, if you’re issuing an Ex command from visual mode, you want to act over the selected region.

Let’s try to convince ourselves of this in the editor. Work through the checklist below: select the first paragraph, drop back to normal mode, then type :'<,'>d into the command line yourself. The paragraph gets deleted, even though we’re no longer in visual mode — Vim preserved the '< and '> marks for us.

  1. Linewise-select the first paragraph The first paragraph spans three lines — put the cursor on the first line, press V, then press j twice.
  2. Return to normal mode, then delete the old selection Hit Escape — the highlight will disappear — then type :'<,'>d and hit Enter. The paragraph will vanish anyway.
Linewise-select the first paragraph The first paragraph spans three lines — put the cursor on the first line, press V, then press j twice.

Next: Return to normal mode, then delete the old selection

Loading editor…