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
/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;
Written by akhilravidas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Related Tags
#vim
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#