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
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityYou 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