66

How can I turn off Emacs's auto line wrapping for the current session?

I normally need the automatic wrapping, but when editing a email draft, I don't need that. Is there a way to turn it off for a while?

3 Answers 3

85

Depending on which flavor of automatic line wrapping you're using, it'll be one of

M-x toggle-truncate-lines

if your lines wrap hard at the right-hand edge of the window, or

M-x visual-line-mode

if your lines "soft wrap" at the whitespace nearest the right-hand edge of the window.

(If you're using an Emacs version older than 24.4, it may also be M-x longlines-mode, if your lines wrap hard at a given column.)

If you've issued the wrong command for your configuration, then the message in the minibuffer will say "...enabled" instead of "...disabled"; in that case, just issue the same command again to re-disable the bogus mode, and try the others until you've found the one which disables the mode you're actually using.

These are buffer-local modes, so issuing the command will affect only the buffer you're in when you do so; in all other buffers, you'll still have the benefit of line wrapping unless you similarly turn off the mode there as well.

Should you wish later to turn line-wrapping back on, just reissue the command you used to disable it.

3
  • 6
    For another culprit implicated in visual line wrapping, try M-x toggle-truncate-lines Oct 22, 2013 at 16:18
  • @BarryKelly Good point! I'd forgotten about that one -- I've just edited the answer to include it. Oct 22, 2013 at 16:32
  • I use it often enough to bind it to a keyboard shortcut by adding (global-set-key (kbd "C-c w") 'toggle-truncate-lines); wrap in my .emacs file. Feb 21, 2016 at 14:57
12

Another possibility may be to toggle auto-fill-mode: Alt + X, auto-fill-mode (tab completion works)

For example, turning off auto-fill-mode in AUCTeX stops hard line wrapping

2
  • 2
    This is the right answer for LaTeX modes. Jan 24, 2020 at 5:28
  • It works for me in all sorts of modes, including text mode.
    – joriki
    Aug 9, 2021 at 8:04
12

Just an update on longlines-mode.

As of Emacs 24.4, longlines-mode no longer exists. Therefore I'd recommend using M-x toggle-truncate-lines if you want it temporarily, or (set-default 'truncate-lines t) in your .emacs file if you want it be default in all buffers

4
  • 1
    I need this effect for the current buffer, or editing session, and in particular, not as a default.
    – qazwsx
    Oct 20, 2015 at 18:28
  • 1
    Ah right, misread the initial question. Just wanted to provide an update that longlines-mode won't work anymore. Updated my answer
    – Connor S
    Oct 21, 2015 at 18:51
  • 1
    This was the only - and also most painless - solution that worked for me. @qazwsx consider changing this to the accepted one?
    – mmlac
    Oct 29, 2015 at 5:50
  • Yes, this works in the current document (Alt + X, toggle-truncate-lines). Sep 29, 2021 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.