4

I'm trying to run a command (from within a function) that goes somewhat like this:

execute a:firstline . ',' . a:last line . 'g/\(\.\|!\|?\)\()\|]\|"\|'\)*\($\|\s\)/execute "normal! v(:call MyFunction()\<cr>"'

But it doesn't work and I think it's because of all the quotes. I tried escaping them with backslashes, but that doesn't work either.

Any ideas?

  • 1
    You're trying hard to shoot yourself in the foot by doing things this way. But if you insist: double the ' in the second group. – Sato Katsura Aug 1 '16 at 18:21
  • @SatoKatsura I don't insist, I just have no idea what I'm doing, haha. Just changed it to your suggestion on Christian's answer. Thanks! – dbmrq Aug 1 '16 at 18:36
5

Either put the quotes into an extra variable and use that, which saves you from the effort to escape them, or double the single quotes. But notes, this makes it really hard to read (and understand) later your regex.

Quote from the help (:h literal-string)

This string is taken as it is. No backslashes are removed or have a special meaning. The only exception is that two quotes stand for one quote.

  • 2
    The regexp could be simplifies like this, I believe: \v[.!?][])"']*($|\s) – Sato Katsura Aug 1 '16 at 18:26
  • Perfect, thank you! – dbmrq Aug 1 '16 at 18:35

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.