I understand you can call a function in a vim search/replace operation. For example:
%s/regex/\=localtime()/g
will replace anything matching 'regex' with the current epoch time. The problem is, I can't add anything else to the 'replace' expression. For example:
%s/regex/epoch: \=localtime()/g
does not treat 'localtime' as a function anymore. Rather it just prints 'epoch: =localtime()' as a string in the replacement text. The intention is for it to print 'epoch: 1353085984' instead.
Is there any way to call a function from within an arbitrary section of a replacement expression?
Once you use a replace-expression, it must be the entire replacement. You can use String concatenation in your expression (and refer to captured elements via submatch(1)
instead of \1
), like this:
:%s/regex/\='epoch: ' . localtime()/g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With