Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim call function on a group in substitute string

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?

like image 231
microo8 Avatar asked Mar 01 '12 08:03

microo8


1 Answers

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

%s/regex/\= function(submatch(1))/g
like image 122
jcollado Avatar answered Sep 30 '22 16:09

jcollado