10

how to call a function from the substitute string in vim? When i have:

%s/regex/string/g and i want the group as argument and replace it with the return value of the function:

%s/regex/call function(\1)/g so the group #1 will be the argument of the function, and the return value of the function will replace all the matches in buffer.

is it posible?

microo8
  • 3,568
  • 5
  • 37
  • 67

1 Answers1

13

To use a vimscript expression you need to add \= to your replacement string:

%s/regex/\= function(submatch(1))/g
jcollado
  • 39,419
  • 8
  • 102
  • 133