26.6.1 Auto Fill Mode

Auto Fill mode is a buffer-local minor mode (see Minor Modes) in which lines are broken automatically when the line becomes too wide and you type SPC or RET.

M-x auto-fill-mode

Enable or disable Auto Fill mode.

SPC
RET

In Auto Fill mode, break lines when appropriate.

The mode command M-x auto-fill-mode toggles Auto Fill mode in the current buffer. Like any other minor mode, with a positive numeric argument, it enables Auto Fill mode, and with a negative argument it disables it. To enable Auto Fill mode automatically in certain major modes, add auto-fill-mode to the mode hooks (see Major Modes). When Auto Fill mode is enabled, the mode indicator ‘Fill’ appears in the mode line (see The Mode Line).

Auto Fill mode breaks lines automatically at the appropriate places whenever lines get longer than the desired width. This line breaking occurs only when you type SPC or RET. If you wish to insert a space or newline without permitting line-breaking, type C-q SPC or C-q C-j respectively. Also, C-o inserts a newline without line breaking.

The place where Auto Fill breaks a line depends on the line’s characters. For characters from ASCII, Latin, and most other scripts Emacs breaks a line on space characters, to keep the words intact. But for CJK scripts, a line can be broken between any two characters. (If you load the kinsoku library, Emacs will avoid breaking a line between certain pairs of CJK characters, where special rules prohibit that.)

When Auto Fill mode breaks a line, it tries to obey the adaptive fill prefix: if a fill prefix can be deduced from the first and/or second line of the current paragraph, it is inserted into the new line (see Adaptive Filling). Otherwise the new line is indented, as though you had typed TAB on it (see Indentation). In a programming language mode, if a line is broken in the middle of a comment, the comment is split by inserting new comment delimiters as appropriate.

Auto Fill mode does not refill entire paragraphs; it breaks lines but does not merge lines. Therefore, editing in the middle of a paragraph can result in a paragraph that is not correctly filled. To fill it, call the explicit fill commands (see Explicit Fill Commands).

A similar feature that wraps long lines automatically at display time is Visual Line Mode (see Visual Line Mode).