apply function to substitution?

0 views
Skip to first unread message

Reckoner

unread,
Mar 30, 2008, 7:50:10 PM3/30/08
to v...@vim.org

is this possible:

:%s/\(.*\)/some_function(\1)/g


where some_function is something I would define myself. Python has this function, BTW.

Thanks in advance.

Tony Mechelynck

unread,
Mar 30, 2008, 8:04:47 PM3/30/08
to vim...@googlegroups.com, v...@vim.org

:%s/.*/\=some_function(submatch(0))/

see
:help sub-replace-special
:help submatch()

Note that since the * operator is greedy, .* matches the whole line,
therefore the g flag doesn't change anything (there is only one whole
line on each line).

Best regards,
Tony.
--
Overdrawn? But I still have checks left!

Reply all
Reply to author
Forward
0 new messages