Emacs has the function fill-paragraph
. Is there any function which will do the opposite of that?
I have a paragraph which is already filled and instead I want it in a plain single line?
Emacs has the function fill-paragraph
. Is there any function which will do the opposite of that?
I have a paragraph which is already filled and instead I want it in a plain single line?
Quoting from Emacs Wiki, by Stefan Monnier:
Unfilling a paragraph joins all the lines in a paragraph into a single line. It is the contrary of FillParagraph.
It works where a line ends with a newline character (”\n”) and paragraphs are separated by blank lines. To make a paragraph end in a single newline then use the function below:
;;; It is the opposite of fill-paragraph (defun unfill-paragraph () "Takes a multi-line paragraph and makes it into a single line of text." (interactive) (let ((fill-column (point-max))) (fill-paragraph nil)))
And to bind it to a key:
;; Handy key definition (define-key global-map "\M-Q" 'unfill-paragraph)
See also UnfillRegion, and UnwrapLine.
My method would be placing the cursor in the last line of the paragraph and hitting M-^ several times.
The beauty of this shortcut is that beside joining lines it reduces any amount of indentation spaces into single one.
There is the unfill
package for this now.
Provides commands for explicitly unfilling (ie. unwrapping) paragraphs and regions, and also a command that will toggle between filling and unfilling the current paragraph or region.
It is based initially on Xah Lee's examples and later rewritten based on an article by Artur Malabarba
It provide the following:
M-x unfill-region
M-x unfill-paragraph
M-x unfill-toggle
It's convenient to add an handy keybinging of your choice like:
;; Allow to fill or unfill with a single keybinding
;; depending of the content status
(global-set-key (kbd "<f8>") 'unfill-toggle)
As always, there are several ways to do this, so I'll throw another answer in the ring:
Mark paragraph: M-h
Query replace newline with space in region:
M-% C-q C-j RET SPC RET !
A poor man's unfill can also be done by first setting the fill-column
to some ridiculously high value (I use 9999) and then filling. For instance, C-u 9999 C-x f M-q C-u 70 C-x f
. (Also, you might prefer C-9 C-9 C-9 C-9
to C-u 9999
.)
In Evil mode there is the J
key binding in normal mode
from VIM. It joins the line below and the current line into one line. So by pressing it multiple times, you can undo fill-paragraph.