I've pasted some text from the Web into Vim editor and for some reason each paragraph is treated as a single line:

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.

I want to re-format the pasted text so that each sentence is treated as a single line. Also want to preserve the "." at the end of the sentence. How can I do this in Vim? Or how can I prevent the pasted paragraph from being treated as a single line in the first place?

:%s/. /\n/g didn't work (even if it would, it would have replaced dot and space with a newline but I want to preserve the dot at the end of each sentence.

Thank you

  • 1
    You might want to look into textwidth and gq – muru Sep 3 '19 at 8:49

:%s/. /\n/g is close, but has three mistakes:

  • . matches any character. TO match a real dot, escape it: \.
  • If you want to preserve the dot, place it in the replacement string (somehow obvious)
  • \n is a null character. Use \r for a newline

Together this is:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.