Last Updated: February 25, 2016
· akhilravidas

Substitute last search pattern


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

 # Add std:: prefix to the search terms

Source file:

string a;
map<string, string> b;

End result:

std::string a;
std::map<std::string, std::string> b;