2010-10-22 84 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