How do I configure Emacs so that line wrapping does not break in the middle of a word?
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).
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)
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.
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.
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.
~/.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)
Success story sharing
visual-line-mode
but was getting annoyed by the waykill-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 butkill-line
still kills the whole line. You may not agree that this is the preferred behaviour, of course, but for me it certainly is.