In Emacs, I have a paragraph of text, which is already properly wrapped at, say 79th column on each row, then you edit it, adding some text on some of the rows, how to reformat the edited paragraph so the line break characters are automatically removed and inserted in correct places such that the resultant paragraph are again line breaking at 79th column for each row, or whatever is proper for the current mode, say python-mode?


You should use the fill-paragraph command, normally bound to meta-q. (You can use ESC q if your keyboard doesn't have a meta key.) Paragraph filling only makes sense in free text modes or within comments in programming language modes. Programming language modes are usually setup around the TAB key to properly indent lines; line breaks are inserted manually.

To set the column at which lines of text are broken, use the set-fill-column command. Place the cursor at the column you want the line to end, and type control-u control-x f and that column will become the fill column for the current buffer. Use fill-paragraph to refill the paragraph with the new fill column.

  • 1
    What do I put in .emacs so the default is such that fill-paragraph makes all rows filled up to the 79th column? – qazwsx Mar 16 '12 at 6:21
  • 6
    (setq-default fill-column 79) – Kyle Jones Mar 16 '12 at 7:22
  • Is there an opposite to fill-paragraph, that would reformat the paragraph to be all on one line? – jameshfisher Dec 12 '14 at 13:45
  • 1
    Oh I found it: unfill-paragraph. Thanks. – jameshfisher Dec 12 '14 at 13:46

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.