next up previous contents
Next: Reformatting Hard Wrapped Documents Up: Formatting Your Text Previous: Formatting Your Text   Contents

Word wrap

Before version 22 word wrap was a bit of a hassle, but things are much better now, so upgrade if you can.10 Word wrap comes in two forms: soft wrap and hard wrap. Hard wrap means that at the end of every line a ``newline'' character is inserted. Most plain text email is sent this way. If you have 80 character wide paragraphs and want them to be 120 characters wide, you have to reformat. Soft wrap means the program recognizes the width of the window on your screen and reformats the words to fit the window, without inserting any newline characters. If you resize the window, the words adjust automatically.

Unless you tell it do otherwise, emacs will let lines wrap around the screen, but make no effort to break the line between words; you'll see a little arrow right in the middle of a word. This is annoying. Better is to enable ``long lines'' mode (M-x long-lines-mode, which permits emacs to leave words intact. The lines will wrap at the margin set with the C-x f command. C-u 80 C-x f sets the width to 80 characters, for example of your paragraph but does not reformat the paragraph. M-q reformats the paragraph.

For hard-wrapped lines (useful, for example, if you're writing a LATEX document), hit C-u 120 C-x f to set the margin, and type M-x auto-fill-mode to toggle auto-fill mode on (check the status bar at the bottom of the screen to see if it's on: look for the word ``fill'' in the mode line). Now start typing. Your paragraphs will be hard wrapped at 120 characters, the width of your screen. Now if you go back to edit your work, the paragraph will be out of whack. Hit M-q to reformat the paragraph. If you later decide you want the paragraph to be 72 characters wide again, you can hit C-u 72 C-x f to set the new margin and M-q to reformat it.

There are two other useful commands available to you if you've selected a region you'd like to format. The command fill-individual paragraphs reformats each paragraph in the region. This is probably what you want if you want to globally change all the paragraphs in your document from 72 to 85 characters wide, for example. The command fill-region-as-paragraph will take all the fragments of text in your region and make them into a single paragraph, removing extraneous blank lines and double spaces, etc. - a very handy way to reformat hacked-up text.


next up previous contents
Next: Reformatting Hard Wrapped Documents Up: Formatting Your Text Previous: Formatting Your Text   Contents
Randall Wood 2011-03-31