5

Is it possible to pass a variable to a function in vimscript, and then use that value in a search and replace regex?

For example:

function! AddTW5Links(tiddlerSetName) 

    %s/\(*\+\)\(\[\[\(.*\)\)\]\]/\1[[\3|\3 - $tiddlerSetName]]/g

endfunction
6

You have the choice between using :s after :exe, or using :s\=.

Meaning (untested)

:exe 's/\(*\+\)\(\[\[\(.*\)\)\]\]/\1[[\3|\3 - '.a:tiddlerSetName.']]/g'

(beware of double-quote, you'll have to double all your backslashes with them)

Or

:s/\(*\+\)\(\[\[\(.*\)\)\]\]/=submatch(1).'[['.submatch(3).'|'.submatch(3).' - '.a:tiddlerSetName.']]'/g

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.