Is there a way to line wrap selected text in TextMate?

8

1

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?

Matt

Posted 2012-02-08T23:15:41.283

Reputation: 193

Answers

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.

Daniel Beck

Posted 2012-02-08T23:15:41.283

Reputation: 98 421

1The menu item may have had its name changed to Reformat Text. – Graham P Heath – 2015-12-10T21:55:22.097

1The column width is now in View >> Wrap Column – mrisher – 2016-04-05T17:40:16.720

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

Graham P Heath

Posted 2012-02-08T23:15:41.283

Reputation: 146

0

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

resamsel

Posted 2012-02-08T23:15:41.283

Reputation: 71

This should just be a comment on that answer. – blm – 2016-01-19T18:34:08.420

I'm not allowed to comment, yet. – resamsel – 2016-01-20T12:52:46.790