Andrew's Digital Garden

Ranges in Vim

Ranges are applied to commands to specify what is affected by the command. Multiple line specifiers can be separated by a comma.

Useful ranges are:

  • <number> - line number
  • . - current line (usually the default range)
  • $ - last line of the current buffer
  • % - current file
  • * - last selection in visual mode

Ranges also support arithmetic, e.g. .+10 will be the current line, plus 10.

'< and '> are also ranges, as used in [[20210531165731-vim-search-replace-visual]]. The former represents the first line selected, and the latter the last line.

Ranges can be used as such:

  • :1,40d - delete line 1 to 40
  • :%d - delete every line
  • .,.+10 - delete current line to current line plus 10

[[vim]]

Ranges in Vim