Ask and Learn
Ask and Learn

Reputation: 8959

Vim current line to end of block

I am trying to figure out how to search/replace from current line to end of block and don't understand why my command

:.,}s/a/b/g

Not working

Upvotes: 0

Views: 101

Answers (2)

Peter Rincker
Peter Rincker

Reputation: 45107

Good news, you have options!

  • If end of block means next paragraph then you can use the '} mark in your command. e.g. :,'}s/foo/bar/. See :h '}
  • If end of block means to the ending } character then you can do as @Dyno Hongjun Fu suggested and use visual mode + a motion. e.g. v]}:s/foo/bar. See :h ]}
  • You can also use a search in your range for a range that doesn't line up directly with any Vim motion. e.g. :,/baz/s/foo/bar. See :h range
  • When in doubt just use visual mode.

Upvotes: 2

Dyno Fu
Dyno Fu

Reputation: 9044

here is the range doc, it seems } is not supported there.

as an alternative, you can first visual select with v} then do your replacement with :'<,'>s/a/b/g

Upvotes: 4

Related Questions