Prettier, why can't you do this?

If you have a chunk of text you’d like to line wrap in a comment block, good for you! Detailed and meaningful comments are so helpful. But what if you use JavaScript and Prettier will not touch comment blocks for some reason and refuses to wrap them?

With macos, there’s a great trick:

  1. Copy the “paragraph” or chunk of text

  2. With your terminal, run this command:

    pbpaste | fmt -w 80 | pbcopy
    

    Definitely try a man fmt for more details.

    fold is another line wrapping tool, but does a little less. That could be useful in other situations too.

  3. Now on your clipboard, you should have a formatted chunk of text that’s perfectly line broken and word wrapped.

There’s probably a linux variant too, if you need it depending on your distribution and other tooling.

Follow me on Mastodon @ryanmr@mastodon.cloud.

Follow me on Twitter @ryanmr.