vim question

Chris Devers cdevers at pobox.com
Wed Mar 26 01:46:32 GMT 2008


On Mar 25, 2008, at 9:31 PM, Chris Devers wrote:
> 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.
>
> 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.

Actually, even then I'd cheat.

Cursor is on the 'b'. Hit [i<return><esc>] to add a line-break there.

Go to the next line ("brown:fox:jumped...").

Strip out all the colons on the newly formed line, which just happens  
to start where you wanted to start.

     :.s/:/ /g

Go back to the previous line, ending in ("The:quick:"). Hit [j] to  
concatenate the next line back onto this one.

Done.

There are surely smarter ways to do this, but they're smarter than I  
am. This took less thinking.


-- 
Chris Devers


More information about the london.pm mailing list