vim search and replace using current line as reference point

You can use . for the current position, and .+10 for 10 lines down:

:.,.+10s/foo/bar/g

Some other useful ranges:

  • % for the whole file. Example: :%s/foo/bar/g.
  • '<,'> for the lines of visually selected block. This might get you more than you want of the visual selection starts or ends in the middle of a line. The whole line is included.
  • 'a,'b from mark a to mark b.
  • .,$ from the current line to the end of the file.

Leave a Comment