You can use & for the entire search pattern, or you can use groups according to the section of the pattern. Using & :
:%s/<search_pattern>/&_foo/g
This will accomplish what you are looking for. If you need something more complicated using groups. To create a group, combine part of the search pattern with a (shielded) bracket. You can then reference this with \n , where n is the group number. An example will better explain this.
You have the following file:
bread,butter,bread,bread,bread,butter,butter,etc
Do you want to change any instance of bread,butter to bread and butter :
:%s/\(bread\),\(butter\)/\1 and \2/g
source share