开发者

Convert line-broken paragraphs into single paragraphs? (Folding text?)

I have searched everywhere for an answer to this, but I think I must not be using the right lingo... I have text like this:

This text is actually just
one paragraph, but every
few words are broken to a
new line, and that's
annoying as hell, because
I have to go to each line
and fix it by hand...

Then there's a second
paragraph which does the
same thing.

I would like to convert that to:

This text is actually just one paragraph, but every few words are broken to a new line, and that's annoying as hell, because I have to go to each line and fix it by hand...

Then there's a second paragraph which does the same thing.

I've tried as many regex techniques as I could think of in TextMate, and can't find any macros or commands to re-wrap the text... The text in question is a result of content editors on one of my sites pasting from Word... I think they may even 开发者_C百科type this way (holdover from typewriter days!).


Based on your comment, there's probably something you can do with lookaheads. I tried it, but it didn't work (perhaps didn't try enough). So you can try to do this with a series of commands.

First replace any series of spaces with just a single space character:

:%s/ \+/ /g

Then replace all newlines with a space:

:%s/\n/ /g

Then replaces all double spaces with double newlines:

:%s/ /^M^M/g

The ^M can be obtained in vim by doing CTRL+V CTRL+M.

Or, you could even do:

:%s/ /\r\r/g

This is a little ghetto, but it should work :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜