将换行段落转换为单个段落? (折叠文字?)

时间:2010-10-22 15:33:20

标签: regex text textmate

我到处寻找答案,但我想我一定不能使用正确的术语......我有这样的文字:

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.

我想将其转换为:

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.

我尝试过在TextMate中可以想到的许多正则表达式技术,并且找不到任何宏或命令来重新包装文本...有问题的文本是内容编辑器的结果之一我的网站从Word中粘贴......我认为他们甚至可以用这种方式打字(从打字机日开始保留!)。

1 个答案:

答案 0 :(得分:1)

根据您的评论,您可以使用前瞻做些事情。我尝试过,但它没有用(也许没有尝试)。因此,您可以尝试使用一系列命令执行此操作。

首先用一个空格字符替换任何一系列空格:

:%s/ \+/ /g

然后用空格替换所有换行符:

:%s/\n/ /g

然后用双换行替换所有双空格:

:%s/ /^M^M/g

^M可以通过 CTRL + V CTRL + M在vim中获得

或者,您甚至可以这样做:

:%s/ /\r\r/g

这是一个小贫民区,但它应该工作:)