31

How do I rewrap a block of text or a long comment to fit 80 columns?

I don't want it to just render the word wrap (this is easily achieved with Edit -> Toggle Word Wrap or setting "editor.wordWrap": "on"), but I want it to actually insert hard line breaks. This feature is called "fill paragraph" in some editors.

For example:

// This is a very long comment. I would like for this comment to occupy multiple lines rather than a single line, so that it is easy to read for other people.

Now I'd like to press some key to get:

// This is a very long comment. I would like for this comment to occupy
// multiple lines rather than a single line, so that it is easy to read for
// other people.
Jo Liss
  • 30,333
  • 19
  • 121
  • 170
  • Looking for a JavaScript solution here that can run as a plugin? Does it have to be language sensitive, such as `#` vs `//`? – tadman Mar 20 '17 at 19:13
  • @tadman You can use built-in class or id to identify comments, since its all html and css. – BladeMight Mar 20 '17 at 19:16
  • @BladeMight Yeah, but the size of the comment delimiter impacts the wrapping, as does any indentation that might be in play. This is superficially simple but might prove to be a little obnoxious to get perfectly right. An interesting challenge. – tadman Mar 20 '17 at 19:17

2 Answers2

26

Looks like Rewrap does what you need. Not sure if there's a native way yet. They're still adding a lot of features.

Sadman Sakib
  • 360
  • 2
  • 8
Captain Stack
  • 3,572
  • 5
  • 31
  • 56
10

VSCodeVim supports this feature. Just select a block of text and press gq. :)

thedayturns
  • 9,723
  • 5
  • 33
  • 41