Dark Secrets of Emacs Word Wrapping

This one is for those that want to prevent Emacs from getting pwned by advanced modern applications like… Notepad.  Heh.

“MS-DOG” users that have been “brain damaged” by Windows generally think of text editors as… well… a text editor. They like Notepad because it’s fast, easy, and it doesn’t do anything to your files behind the scenes like just about every other frickin’ Windows program.

Now, for just the general “I’m not going to do any serious editing, I just want to rt-click -> Open this text file and scroll around on it to see what’s going on” type of thing, Notepad has this truly tremendous feature called “Word Wrap.” If it’s on, you get soft word wraps added to your text to make it more readable. As is standard in the Notepad way, this does not do anything to your file, it’s just a feature to make it look good on the screen whether you resize it or not. If you turn word-wrap off then you don’t get any wrapping at all– this is good for looking at files that have fixed length columns.

Emacs defaults to a form of wrapping that puts in “soft line breaks” where ever a line goes off the screen. These are marked on either side with little squiggle arrows. This approach has its merits in that you can see all of your file on screen at one time in a mostly sort-of kind-of the way it is sort-of way. To turn this off, type M-x toggle-truncate-lines. Now you will have a text editor that’s almost as good as notepad with “Word Wrap” turned off! 😉 This should make the wrapping lines extend off the right side of the screen.  Note that this command makes using the SQL mode much nicer… though sql-ms/isql still screws up your column headings with the timer text: “1> 2> 3> 4>”.

One core NotePad feature has only recently become available to Emacs users via Emacs 22. M-x longlines turns the feature on, after which M-x longlines-mode toggles it on and off.  Longlines mode gives you the easy reading soft word wrapping of NotePad with “Word Wrap” turned on.

Note that, splitting the screen horizontally vertically with C-x 3 seems to give you “Word Wrap Off” huge lines scrolling off the screen whether you want it or not. And no horizontal scroll bar for you, either! The only way to see the text that is off-screen in this case appears to be to scroll by hitting C-x > and/or C-x <. Alternately you can resize the windows a bit by hitting C-x } and/or C-x {. (For that last one you may want to use the repeat command of C-x z and then as many z‘s as you want after that. But don’t blame me if you accidentally shut down Emacs when you try But don’t blame me if you accidentally shut down Emacs when you try this!) If you really have to use the mouse, then you can click on the arrows on either side of the frame/window/whatever.

8 Responses to “Dark Secrets of Emacs Word Wrapping”

  1. Replacing MS SQL “Enterprise Manager” with Emacs « Learning Lisp Says:

    […] the Word-Wrap nightmare while in the sql-mode with M-x […]

  2. sz Says:

    as for C-x 3 (split-window-horizontally) disabling the word wrap, i found the solution:
    C-h v truncate-partial-width-windows, go to “customize” and toggle the value.
    it’s so simple! (and i thought it was a bug!)

  3. lispy Says:

    I’m experimenting with this even as I type…

    I noticed a small error. C-x 3 splits the window vertically not horizontally (as my post formerly stated.)

    Holy cow… it works!!

    I was going to say that it didn’t, but when you customize the variable… you have to be sure to hit the “Set for Current Session” in order to get the value toggle to actually be applied.

    Thank you!! You are an Emacs hero!

  4. Erik Says:

    Thank you, I knew there had to be a way to do this (there’s always a way to do everything in Emacs)!

  5. Erik Says:

    As an alternative to the customize route, you should be able to put the following line in your .emacs

    (setq truncate-partial-width-windows nil)

  6. Emacs Word Wrap « In The Armchair Says:

    […] in emacs isn’t automatic, but here’s how it can be done. I found these instructions at https://lispy.wordpress.com/2007/07/12/dark-secrets-of-emacs-word-wrapping/. It’s not perfect; despite the comments on that website, I don’t yet know how to make […]

  7. baongoc124 Says:

    How about “M-x toggle-word-wrap”?

Leave a comment