Vim

Vim - 如何用換行符替換點後的空格?

  • September 3, 2019

我將一些來自 Web 的文本粘貼到 Vim 編輯器中,出於某種原因,每個段落都被視為一行:

PROD $ egrep -i 'system' text
Hurricane Dorian is a strong tropical cyclone currently affecting the Bahamas and the Southeastern United States. The fourth named storm, second hurricane, and first major hurricane of the 2019 Atlantic hurricane season, Dorian developed from a tropical wave on August 24 in the Central Atlantic. The system gradually intensified while moving toward the Lesser Antilles, before becoming a hurricane on August 28. Rapid intensification ensued, and on August 31, Dorian intensified into a Category 4 major hurricane. On the following day, Dorian reached Category 5 intensity, peaking with one-minute sustained winds of 185 mph (295 km/h) and a minimum central pressure of 910 millibars (26.87 inHg) while making landfall in Elbow Cay, Bahamas, at 16:40 UTC. Dorian made another landfall on Grand Bahama several hours later, near the same intensity.

我想重新格式化粘貼的文本,以便將每個句子視為一行。還想保留“。” 在句末。我怎樣才能在 Vim 中做到這一點?或者我怎樣才能防止粘貼的段落首先被視為單行?

:%s/. /\n/g沒用(即使可以,它也會用換行符替換點和空格,但我想保留每個句子末尾的點。

謝謝

:%s/. /\n/g很接近,但有三個錯誤:

  • .匹配任何字元。要匹配一個真實的點,請轉義它:\.
  • 如果要保留點,請將其放在替換字元串中(有些明顯)
  • \n是一個空字元。用於\r換行

這一起是:

:%s/\. /.\r/g

引用自:https://unix.stackexchange.com/questions/538811