Vim - 如何用换行符替换点后的空格?

Vim - 如何用换行符替换点后的空格?

我已将一些文本从 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不起作用(即使可以,它也会用换行符替换点和空格,但我想保留每个句子末尾的点。

谢谢

答案1

:%s/. /\n/g很接近,但存在三个错误:

  • .匹配任何字符。要匹配真实的点,请转义它:\.
  • 如果您想保留点,请将其放在替换字符串中(某种程度上很明显)
  • \n是一个空字符。用于\r换行符

合起来就是:

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

相关内容