1

I would like to have replace function which result will be used as replacement, and it takes match as an input.

This is something available in some languages (Lua for instance).

For instance, imagine I have a list of sites in a text and I want to replace them with ping values.

3
  • Have you been able to write a function and just don't know how to use it in find replace syntax?
    – Jeff B
    Dec 13, 2012 at 17:53
  • 1
    What? Could you give us an example of the desired behaviour?
    – romainl
    Dec 13, 2012 at 17:54
  • Re-reading your question, are you looking for :help substitute() or… simply :s/foo/bar?
    – romainl
    Dec 13, 2012 at 19:13

1 Answer 1

4

You can make your replacement pattern an expression by starting it with \=, so you can call functions that way and pass to that function sub-matches with the submatch() function, for example:

:%s/foo .*/\=Foo(submatch(0))/g

(Remember that sub-match 0 always means the whole matched pattern.)

See:

:help sub-replace-expression
:help submatch()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .