On 06/20/2011 07:19 AM, rameo wrote:
On Jun 20, 1:50 am, Tim Chase<[email protected]>  wrote:
hello this is an example, hello to everybody
example hello

   I do a search for hello

My output has to be:

hellohello
hello

or

hello hello
hello

My first thought would be something like

    :%s/\w\+/\=submatch(0)=~'pattern'?submatch(0):''

or perhaps

    :%s/\w\+\W*/\=submatch(0)=~'pattern'?submatch(0):''

This assumes your pattern is a single-word.  You'd have to expand
your search expression to accommodate if it's more than a
single-word.  You're basically chunking it up into pieces you can
match your pattern against, and then, if the pattern doesn't
match, replacing it with an empty string ('')

I checked it but it doesn't do what I would like it does :(

It worked on the sample text and search-string you provided (granted, using "hello" for "pattern"). So if something didn't work, you'd need to provide more real-world text & patterns.

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to