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?

Utku
  • 305
  • 2
  • 6

2 Answers2

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.

VanLaser
  • 9,700
  • 2
  • 24
  • 34
  • 2
    are you sure about the 're' engine thing? I don't see how this makes a difference. – Christian Brabandt Dec 14 '15 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 '15 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.

jamessan
  • 11,045
  • 2
  • 38
  • 53