0

I have this substitution, which does not work:

exe 's/<<\(.*\)\%(,.*\)\?>>/<<\1,'.system('ark headings \1 | head -1').'>>'

What I want to do is:

  • capture some expression within double angle brackets: <<\(.*\)>>

  • paste opening double angle brackets back, followed by expression and comma: <<\1,

  • and then paste it after filtering it through some external command: system('foo \1 | head -1 | cut -f1')

  • follow it with the closing double angle brackets: >>

But I can't get the expression to work...

1

The system function is called before the search-replace is executed. It is called to generate the command.

What you can do is:

s/<<\(.*\)\%(,.*\)\?>>/\='<<'.submatch(1).','.system('ark headings '.submatch(1).' | head -1').'>>'/

The \= tells Vim that the substitute string is a expression, that should be evaluated on every replace.

See :help sub-replace-expression and :help submatch().

BTW: I'm not sure what <<\(.*\)\%(,.*\)\?>> should match. The \(.*\) will match everything until the >>. I guess you want <<\([^,]*\).*>> or <<\([^,]*\).\{-}>>.

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.