Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 12 down vote accepted

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.

share|improve this answer
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
5  
(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? –  eegg Dec 12 at 13:45
    
Oh I found it: unfill-paragraph. Thanks. –  eegg Dec 12 at 13:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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