Emacs has a “fill-paragraph” command. The command add line breaks in the current paragraph, so that each line is no more than about 70 chars. However, there's no “unfill-paragraph” — a command that does the reverse. Here's the solution.
(defun unfill-paragraph () "Replace newline chars in current paragraph by single spaces. This command does the reverse of `fill-paragraph'." (interactive) (let ((fill-column 90002000)) (fill-paragraph nil))) (defun unfill-region (start end) "Replace newline chars in region by single spaces. This command does the reverse of `fill-region'." (interactive "r") (let ((fill-column 90002000)) (fill-region start end)))
You can define a keyboard shortcut for them.
The above code works by setting the variable “fill-column” to a large value then call “fill-paragraph” to do the work.
A even better command is “compact-uncompact-block”. It automatically “fill” or “unfill” depending on whether the current paragraph is already “filled”. Also, it automatically works on the current text selection if there's one, so you don't need to choose between “*-paragraph” or “-region” versions. See: Emacs's Line Wrap Commands: fill-region, unfill-region, compact-uncompact-block.