0

What is the appropriate way to make a pattern that matches up until the point where the move command e would have moved to?

Consider this text: texttext%0s: cookie after performing /%<CR>ve the part %0s would be selected, this is the part I want to replace with something else.

I tried :s/%.\{-}\> which seems to match the right thing (as little as possible until end of word) but I'm not sure if it's 100% correct and how to interpret the manual:

:help \>

\>      Matches the end of a word: The previous char is the last char of a
        word.  The 'iskeyword' option specifies what is a word character.

:help e

e                       Forward to the end of word [count] inclusive.
                        Does not stop in an empty line.

Is the only difference that e moves past newlines?

1

Yes, it is equivalent, except as you say it doesn't span lines.

First the \> matches a "end of a word" ( as defined by iskeyword). So it matches something that you could reach with the e command.

The important part is the .\{-}. With it the the expression .\{-}\> becomes "match from here to the next "end of word" in the same line. This is the same as e.

In contrast .*\> means "match from here to the last end of word in the current line".

The . does not match line breaks, but \_. does. So %\_.\{-}\> would match

%
word
| improve this answer | |
  • Question title updated. One difference is that e reaches past line ends, which the pattern by default does not do (since . doesn't match newline). – Moberg May 11 at 22:04
  • @Moberg That with the title and text was nice chance for a joke. Should have put a smiley. You are right about end of line, will update. – Ralf May 12 at 3:46

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.