Ranges
A range is used to tell Vim “I’m talking about this range of lines”. A range is specified as two addresses — the lines between the two addressed lines (inclusive) constitute the range.
To specify an range, you prefix the command like so:
:[address1],[address2]command
If command supports an range, this will cause it to operate on the range you’ve specified. The range is inclusive, so the range 1,3 will operate over lines 1, 2, and 3.
For example, if you wanted to delete the first ten lines in the buffer, you could use:
:1,10d
There is only one special range, and it’s one that you might have seen before: %. The % range is a synonym for 1,$ — that is, it captures all of the lines in the buffer. For example, :%d will delete all of the lines in the buffer (if you’re feeling bold).
The great thing about ranges is that the upper and lower bounds are just addresses. You can use all of the powerful Ex mode addressing tricks we’ve discussed above to specify a range! For example:
:/foo/,/bar/dwill move to the next line matchingfooand delete from there until the next line matchingbar:/foo/+1,/bar/-1dwill do the same as above, but won’t delete thefooandbarlines.
Let’s try this in the editor. Follow the instructions in the buffer.