How can I enable line wrap on word boundaries only in Emacs?

Emacs

Emacs Problem Overview


How do I configure Emacs so that line wrapping does not break in the middle of a word?

Emacs Solutions


Solution 1 - Emacs

If you want to emulate the behavior of an editor like Notepad, you might want to turn on visual line mode. While setting word-wrap will cause line wrapping at word boundaries, any action you take on a line (e.g., moving up/down or killing) will still respect the newline character. Visual line mode will treat each display line as though it had a newline at the end.

(visual-line-mode t)

Line to add in .emacs file:

(global-visual-line-mode t)

Solution 2 - Emacs

M-x toggle-truncate-lines disable allows you to disable visually line breaking.

M-x auto-fill-mode + M-q allows you to word wrap for real a pre-existing paragraph.

Solution 3 - Emacs

Add this to your init file:

(setq-default word-wrap t)

Alternatively, press C-h vword-wrap in Emacs and follow the "customize" link near the end.

Solution 4 - Emacs

I discovered longlines-mode only recently (I think I was spelunking through the Emacs Info documentation). It wraps as you would expect in other UI editors' word-wrap feature. It's especially useful when I'm reading or writing free text with no newlines (a la Microsoft Word) without the ugly mid-word wrapping that happens when you use M-x toggle-word-wrap.

See LongLines.

My configuration:

(setq longlines-wrap-follows-window-size t)
(global-set-key [(control meta l)] 'longlines-mode)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYufeiView Question on Stackoverflow
Solution 1 - EmacsKirk KelseyView Answer on Stackoverflow
Solution 2 - EmacsDoomsdayView Answer on Stackoverflow
Solution 3 - EmacshuaiyuanView Answer on Stackoverflow
Solution 4 - EmacsrgiarView Answer on Stackoverflow