Hi,

Muhammad Farooq-i-Azam wrote:
>
> I have to replace every occurrence of % in a file with
> % |. I have been effectively replacing text using the
> following construct:
> 
> :%s/\<text\>/replacement/g
> 
> However when I try to do the following:
> 
> :%s/\<%\>/% |/g 
> 
> I am greeted by an error message. Obviously, the %
> character needs to be treated differently for being
> replaced. Escap sequence? I cannot figure out how to
> do it. May be trivial for the gurus here. I will be 
> thankful for a hint.

normally % is not included in the 'iskeyword' option so it is not
considered part of a word. Therefore there can not be the beginning of
a word right in front of %. The same is for true for the end of a word
immediately after a %. You either have to include % in the 'iskeyword'
option by issuing a

  :set iskeyword+=%

before executing your substitute command or use

 :%s/%/% |/g

without '\<' and '\>', respectively.

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

Reply via email to