Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I sometimes write long comments in my code. I hate manually wrapping them after 80 characters, and rewrapping them if I edit the comment. Is there a way (or a bundle) that will apply an 80 character line wrap to some selected text?

share|improve this question
up vote 9 down vote accepted

Text » Reformat Selection. It rewraps the current paragraph and uses the wrap column configurable in Edit » Wrap Column for the resulting line width.

For this command, any contiguous series of lines is a paragraph, so if you wrapped it once, then edited something in the middle or changed the wrap column, you can just run it again and it'll fix the line wraps. Use an empty line as separator.

To unwrap again, select Text » Unwrap Selection.


TextMate also supports automatic line wrapping of long lines via View » Soft Wrap.

share|improve this answer
1  
The menu item may have had its name changed to Reformat Text. – Graham P Heath Dec 10 '15 at 21:55

In addition to Daniel's answer;

It's fairly easy to create a macro that only selects the current line, and this seems like a great time to do a little macro demo.

Macros: How To (Creating a Wrap Line macro)

  1. Open Textmate.

  2. Pick a line of text that is longer than your wrap column.

  3. Click the record icon in the bottom right of TextMate's window.

  4. Select the whole line with Command + Shift + L

  5. Open the "Select Bundle Item" dialog with Press Command + Control + T

  6. Search for "Reformat Text", press enter when it is selected.

  7. Using the Edit menu, select Macros -> Save Macro

  8. Select a bundle to add the macro to.

  9. Textmate will open the Bundle Editor with your macro inserted into the bundle you selected and open.

  10. You should have the code in the below section. If you did something other than indicated in these instructions you may wish to modify your macro manually or start over. You can remove a bundle item, such as your macro, with Command + Delete.

  11. (Optional) Add a keybinding of your choice to your macro.

Code:

(
  {  command = 'selectHardLine:'; },
  {  command = 'reformatText:'; },
)
share|improve this answer

Another addition to Daniels answer: The default shortcut is Control + Q.

share|improve this answer
    
This should just be a comment on that answer. – blm Jan 19 at 18:34
    
I'm not allowed to comment, yet. – resamsel Jan 20 at 12:52

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.