e7l7_q
Last Updated: February 25, 2016
·
319
· akhilravidas

Substitute last search pattern

vim

When the substitute command :s is given no argument, it takes the last search pattern as the match string. This is really helpful when working with complex substitute patterns like regexes or when combined with * (searches for word under the cursor)

For example:

# Find all references of string or map
/string\|map

 # Add std:: prefix to the search terms
 :%s//std::\0/g

Source file:

string a;
map<string, string> b;

End result:

std::string a;
std::map<std::string, std::string> b;
Say Thanks
Respond
Filed Under

Awesome Job

A3e45f3a cade 11e7 83bc 71c9546a2749
Systems Engineer
·
Fulton, Maryland or Remote
·
Full Time