vim question

Chris Devers cdevers at pobox.com
Wed Mar 26 01:31:08 GMT 2008


On Mar 25, 2008, at 8:12 PM, asmith9983 at gmail.com wrote:
> I have the following file contents which I'm editing with vim:-
>
>     1  The quick brown fox jumped over the lazy dog.
>     2  The:quick:brown:fox:jumped:over:the:lazy:dog.
>     3  The quick brown fox jumped over the lazy dog.
>     4  The quick brown fox jumped over the lazy dog.
>     5  The quick brown fox jumped over the lazy dog.
>
> I want to place my cursor on the b of brown on line 2, and with a  
> simple
> command change all the colons(:) to end of line,  to a space( ).  
> Obviously its a change to end
> of line only, so a g substitute modifier is no good. I've also tried  
> selecting
> selecting to end of line with v, visual mode, then applying !  
> operator with
> sed -e 's/:/ /', but it didn't work.
>
> Anybody got an idea that'll work.

I _started_ to do a crazy regex substitute thingy, before realizing  
that it was far more work than it would be to just edit it by hand. So  
forget that.

This is much simpler:

     :%s/:/ /gc

It'll offer to swap all the colons for spaces (all lines, all  
instances) asking for confirmation each time. Say [n]o to the first  
two, then [y]es to the rest of them. Done.

If you're giving a simplified example of something more complex, maybe  
a more complex solution closer to what you asked for would be in  
order. But the above is how I'd solve it as you specified it.

-- 
Chris Devers


More information about the london.pm mailing list