Vim substitute

Updated: 16 March 2024

Capture groups

Given the following

one foo one
one bar one

this substitution :s/one\(.*\)one/two\1two/ yields

two foo two
two bar two

Replace text with a new line

Given the following

phpdoc_separation, blank_line_before_statement, ordered_imports
class_attributes_separation, phpdoc_summary, phpdoc_separation

this substitution :s/, /\r/g yields

phpdoc_separation
blank_line_before_statement
ordered_imports
class_attributes_separation
phpdoc_summary
phpdoc_separation

Case

Use I. The following will replace stays but not Stays

:%s/stays/country/gI

Leave a comment