Emacs: Hard Wrap Lines, fill

By Xah Lee. Date: . Last updated: .
emacs fill-paragraph
emacs M-x fill-paragraph
Alt+x fill-paragraphAlt+q
Break a long line into multiple lines. (by inserting newline characters.)
Alt+x fill-region
Break lines in a text selection.
Alt+x auto-fill-mode
Automatically insert newline character as you type.
Alt+x set-fill-columnCtrl+x f
Set the max characters per line used by “fill” commands.
Alt+x ruler-mode
Turn on ruler.

unfill-paragraph, unfill-region

Emacs does not have a “unfill-paragraph” command to do the inverse of “fill”. Here's the solution:

(defun xah-unfill-paragraph ()
  "Replace newline chars in current paragraph by single spaces.
This command does the inverse of `fill-paragraph'.

URL `http://xahlee.info/emacs/emacs/emacs_unfill-paragraph.html'
Version 2016-07-13"
  (interactive)
  (let ((fill-column most-positive-fixnum))
    (fill-paragraph)))
(defun xah-unfill-region (start end)
  "Replace newline chars in region by single spaces.
This command does the inverse of `fill-region'.

URL `http://xahlee.info/emacs/emacs/emacs_unfill-paragraph.html'
Version 2016-07-13"
  (interactive "r")
  (let ((fill-column most-positive-fixnum))
    (fill-region start end)))

The following are better commands for “unfill”:

Line Wrap

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Emacs Tutorial

Quick Start

Font

Split Window

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Editing Brackets

Org Mode

HTML

Emacs Efficiency

Misc