Emacs: Hard-Wrap Lines (fill-paragraph)

By Xah Lee. Date: . Last updated: .

Reformat Long Line to Multiple Short Lines

Alt+x fill-paragraphAlt+q
Break a long line into multiple lines. (by inserting newline characters.)
emacs fill-paragraph
emacs fill-paragraph
Alt+x fill-region
reformat a text selection into multiple short lines.
Alt+x auto-fill-mode
toggle auto-fill-mode.

When on, automatically insert newline character as you type when line reaches the right margin (fill-column).

put this in your Emacs Init File:

;; auto hard-wrap lines
(auto-fill-mode 1)

Variable. The number of chars before fill-paragraph etc commands kicks in.

(setq fill-column 70)
;; default is 70
Alt+x set-fill-columnCtrl+x f
Set the max characters per line used by “fill” commands.

Note: these commands insert newline characters into your file. This type of wrapping is called hard-wrap. Hard-wrap convention of 80 chars came from punched card. You should avoid hard-wrap when possible; add newline char only at logical positions. (Rant: The Harm of hard-wrapping Lines.)

make sentence ending by single space

When Alt+x fill-paragraph etc, emacs reformat it so that there are 2 spaces after a period.

;; make sentence ending by single space
(setq sentence-end-double-space nil )

Emacs Lines, Column, Cursor Position

Soft-Wrap Lines

Reformat Lines (Hard-Wrap)

Show Line Number, Column Number

Highlight Current Line, Screen Line