How do I configure Emacs so that line wrapping does not break in the middle of a word?
-
Do you want to change the display, or where newline characters are inserted? – Ken Jul 19 '10 at 13:57
-
Just the display. Similar to the behavior of MS Notepad. – Yufei Zhao Jul 19 '10 at 13:59
-
11Not sure what version of Notepad you're using, but certainly as of version 6.1 (comes with Windows 7) it definitely does NOT save the line break. I've never actually known it to do this. While I've never defended notepad for anything before, in terms of word wrap, it implements this feature exactly perfectly (and no internet discussion!) whereas each query into how emacs does word wrap *always* gives you like 15 different ways of doing it on 100 different websites, blogs, posts, etc., when the poster 99% of the time just wants it to work like every other modern text editor/viewer. – Sonicsmooth Jul 25 '12 at 04:36
-
For the original misleading title (that may turn up in search engine results), see e.g. *[How can I turn off Emacs's auto line wrapping for the current session?](https://superuser.com/questions/592154/how-can-i-turn-off-emacss-auto-line-wrapping-for-the-current-session/988843#988843)*. `Alt` + `X`, `toggle-truncate-lines` (tab completion works) will turn word wrapping off for the current document. To make it permanent, `vi ~/.emacs` and add this line: `(set-default 'truncate-lines t)` (yes, only one single quote). – Peter Mortensen Sep 29 '21 at 16:39
4 Answers
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)

- 8,099
- 11
- 66
- 91

- 4,259
- 1
- 23
- 26
-
23I was using `visual-line-mode` but was getting annoyed by the way `kill-line` then only killed up as far as the wrap, so for long lines of text (ie paragraphs!) I had to call it repeatedly to delete the line. So now I use `(setq-default word-wrap t)` instead; this enables wrapping but `kill-line` still kills the whole line. You may not agree that this is the preferred behaviour, of course, but for me it certainly is. – gimboland Jun 01 '13 at 18:33
-
@gimboland Thanks. Your recommendation was exactly what I was looking for. – Timothy C. Quinn Mar 27 '14 at 17:37
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.

- 30,738
- 21
- 105
- 131

- 2,650
- 25
- 33
-
1When you say "for real" does that mean that emacs will put in a newline? – 2NinerRomeo May 20 '11 at 17:12
-
I noticed it works for the new lines in an existing org file. But it doesn't wrap the existing lines that are long. Any idea how to wrap the existing lines at a certain col (i.e 80) in an org file? Thanks – Stryker Oct 18 '17 at 00:57
-
`M-q` runs `fill-paragraph`, which will wrap already existing lines of text. The variable `fill-column` determines the line length of the wrapped text. – Soupy Oct 06 '21 at 19:04
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.

- 26,129
- 5
- 57
- 63
-
1
-
Where is the init file located? Can you provide an example location? Is it file `~/.emacs`? – Peter Mortensen Sep 29 '21 at 15:35
-
@PeterMortensen The following init files are tried in this order: `~/.emacs.el`, `~/.emacs`, `~/.emacs.d/init.el` . I prefer the last one since it allows me to put other stuff I may need in a dir dedicated to Emacs – Harry Aug 30 '22 at 09:30
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)

- 30,738
- 21
- 105
- 131

- 1,688
- 18
- 10
-
3According to the wiki, long lines mode is deprecated in favor of visual line mode (mentioned in Anton's answer below. – Eric Anderson Feb 14 '17 at 19:44
-
In which file (incl. location) should the configuration be placed? – Peter Mortensen Sep 29 '21 at 15:44