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?

  • 2
    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. Commented Aug 1, 2016 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
    Commented Aug 1, 2016 at 18:36

1 Answer 1


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) Commented Aug 1, 2016 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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