8

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?

3 Answers 3

10

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.

3
  • 1
    The menu item may have had its name changed to Reformat Text. Dec 10, 2015 at 21:55
  • 1
    The column width is now in View >> Wrap Column
    – mrisher
    Apr 5, 2016 at 17:40
  • Reformat Text will not correctly reformat comments that require a prefix at the start of each line (such as // C++-style and # shell style comments). Tested in TextMate 2.0.23.
    – p00ya
    Dec 23, 2021 at 12:30
1

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

2
  • This should just be a comment on that answer.
    – blm
    Jan 19, 2016 at 18:34
  • I'm not allowed to comment, yet.
    – resamsel
    Jan 20, 2016 at 12:52
0

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:'; },
)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .