← All lessons

18. Ex Commands Addresses And Ranges

Step 2 of 6

Addresses

Most Ex commands can be optionally preceded by either an address or range that the command should operate on. We’re going to talk about addresses in this section. An address is just a line specifier — they’re used to tell Vim “I’m talking about this line”.

Addresses

To specify an address, you prefix the command like so:

:[address]command

If command supports an address, this will cause it to operate on the address you’ve specified.

For example, if you wanted to delete the 10th line in the buffer, you could use:

:10d

The most basic example of an address is a literal line number, like what we’ve done above. But there are various ‘special’ addresses that are well worth remembering. We’re going to look at these in the next section.

In a sentence, addresses can be used to precisely specify lines.

Let’s give it a try in the editor. Try deleting line 10, 20, and 30 with :10d, :20d, and :30d. Keep in mind that you’ll have to delete line 30 first, line 20 second, and line 10 last if you don’t want the line numbers to change!

Loading editor…