I am using the following regular expression to match a documentation string underneath a Clojure function definition:\vdefn.*\n\s*\zs([^]|\n)*Is there a way to run the normal mode gq (format lines) command on all matches of this pattern in a given file?
Apply normal mode command to regex matches
regular expression;substitute
Power of g::g/\vdefn.*\n\s*\zs([^]|\n)*/normal gngqThe part between the /s is fairly self-explanatory, since it's the regex from your original question.normal gngq at the end is somewhat interesting. gn will select the next match of the regular expression, and gq, of course, formats this selection (as you mentioned in your question).:g is the really great part. This is, in my opinion, one of Vim's most useful features. The g ex command takes a regex and an Ex command, and it executes the command on every line the regex matches. If you haven't learned about :g already, I highly recommend doing so, as it'll vastly increase your productivity. A few resources are Vim's own :help :g or Power of g on Vim wiki.