Emacs: Hard Wrap Lines

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://ergoemacs.org/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://ergoemacs.org/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

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Tutorial

Quick Start

Manage Windows

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Working with Brackets

Org Mode

HTML

Emacs Efficiency

Misc