torbonde
torbonde

Reputation: 2459

Emacs word wrap at a specific column number

I like to run my editor full-screen. The only thing is, though, that when I do this, the word wrap only kicks in when the line hits the right edge of the screen. I would like it to do so, already when the line hits, say, column number 200.

How do I do that?

I would like it to happen in all modes, e.g., Org-mode. I added the line (global-visual-line-mode t) to my .emacs file, in order for the word wrapping also to work in org-mode.

I'm running Emacs 23.


I got it working! Here is what I added to my .emacs file to make it happen:

(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook
  '(lambda() (set-fill-column 80)))

Upvotes: 47

Views: 23191

Answers (4)

choroba
choroba

Reputation: 241758

You can set the line width with C-xf (set-fill-column).

Afterwards, you might need to hit M-q to reformat the current paragraph (fill-paragraph), or select text to be justified and run fill-region.

Upvotes: 25

Glyph
Glyph

Reputation: 31860

The suggestion for turn-on-auto-fill will work if you want hard newlines in the files you're editing. If not, and you just want word-wrap, consider instead visual-fill-column-mode, which just does the normal word-wrap that would happen at the edge of the window, but at the specified fill-column.

Upvotes: 10

Drew
Drew

Reputation: 30701

See the Emacs manual (C-h r), node Filling. See in particular the first subnode in the menu, Auto Fill.

Upvotes: 5

Thomas
Thomas

Reputation: 17412

Type M-x auto-fill-mode to activate automatic line-wrapping after a certain column. Then set the actual line width through the variable fill-column as described by user choroba (C-x f).

Note though that this works a bit differently from what other text editors do. M-q will re-format the current paragraph.

Upvotes: 51

Related Questions