9

I have words like lblSERINOd in sentences. Words are separated by white space.

I want to replace the d at the end of all such words with u. So for example lblSERINOd will look like lblSERINOu.

I have tried s/.*\ud /u /g but Vim says it cannot find .*\ud.

What is the problem here?

2 Answers 2

10

One way to do it would be this:

:%s/\u\zsd\>/u/g

Initially I assumed that the new Vim regex engine (being advertised as "faster, but limited") can't understand \u in :substitute, but this isn't the case. I rather think now that the OP forgot to use % and simply searched on the wrong line; this would explain the error message, but of course still needs to be confirmed as "the" cause.

2
  • 2
    are you sure about the 're' engine thing? I don't see how this makes a difference. Dec 14, 2015 at 15:23
  • Nope, not sure at all ... I did a quick test that didn't work, then re-read about pattern in the help file, saw mentioned that the new engine is more limited than the old one, assumed that's the cause ... my first test was rather/possibly flawed
    – VanLaser
    Dec 14, 2015 at 16:25
5

It looks like you may have changed Vim's 'magic' option from its default to 'nomagic'. You can check this with the command

:verbose set magic?

As documented at :help /magic, 'nomagic' causes the . in a regexp to be treated as a literal dot instead of the metacharacter meaning "match any character".

I would highly recommend leaving this option at its default value. This is one of a few options that really shouldn't exist and can cause subtle problems in plugins.

Your Answer

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

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