How to run a search and replace with regex group capture substitution in VIM

Problem: you have a very large string to search and replace.
You want to use a regex for that (probably it is also the only way).
You want to use VIM.

To search across the whole file in VIM you need:


Then you want to add a regex, and since you want a group you have two options: escape all the parenthesis which I don’t want or use the special VIM very magic mode: \v.

Now you search for the group on the main part of the regex and substitute in the second:


This way you can export them all. In my case, I had a very large file (SQL Dump) where I had to convert binary values to use utf8mb4, so I wanted to run this:

:%s/\v(X'[^,\)]*')/CONVERT(\1 using utf8mb4)/g