2010-10-22 167 views
0

我也到处去寻找一个答案,但我想我不能使用正确的行话(?折叠文本)......我的文字是这样的:将换行的段落转换为单个段落?

 
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

根据您的评论,您可能会对lookahead做些事。我试了一下,但没有奏效(可能没有足够的尝试)。所以你可以试着用一系列命令来做到这一点。

首先只是一个单一的空格字符替换任何系列的空间:

:%s/\n/ /g

然后替换所有的双位双:

:%s/ \+/ /g

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

:%s/ /^M^M/g

^M可以vim通过执行CTRL + VCTRL + 中号来获得。

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

:%s/ /\r\r/g

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

+0

我可以做的TextMate,随着搜索正则表达式/替换,但如果我这样做,它也将所有段落放在一起... – geerlingguy 2010-10-22 15:52:58

+0

作品!我只需要将它包装成一个脚本或宏,我会变成金。谢谢 :) – geerlingguy 2010-10-22 16:34:44