1

The raw text is like this:

<words> command feed world </words> tag=random      
<words> who is that ? </words> tag=normal

I need to substitute words for characters:

<words> c o m m a n d  f e e d  w o r l d </words> tag=random
<words> w h o  i s  t h a t ? </words> tag=normal

I know how to do it if the range is over lines, but don't know how to do it if the range is in a line..

My solution:

%s:<words>.*\zs(.)\ze.*</words>:\1 :gc

Without any doubt it does not work.

1

Are you sure you've formatted that example correctly? Some of the spacing seems a bit arbitrary and doesn't seem straightforward to get right:

:%s:\(<words> .*\)\@<=\a\( \A\)\@!\(.* </words>\)\@=:& :g

In particular see :h \@<= for checking for the existence of a preceding item, and :h \@! and :h \@= for negative and positive assertions at the cursor position.

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.