how to replace string with result of function in Vim?
vim
Solution
You can use `\=`. For example:
:s@_debug('\zs@\=printf('(%s:%d) ', expand('%:t'), line('.'))@
When the {replacement} starts with `"\="` it is evaluated as an expression,
Problem
I want to insert filename and line number into some places in the file. For example this line: ``` _debug('init'); ``` I want to replace ``` :s/debug('/debug('(%current_filename_here%:%current_line_number_here%)\ /g ``` to get this ``` _debug('(filename.ext:88) init'); ``` I try to use expand(`'%:t'`) to get filename and line(`"."`) to get line number, but I don't know how to use it in replace expression. How can I do this?