Search code examples
visual-studio-code

Automatically hard wrap lines at column in VSCode


How can I automatically hard wrap lines in VSCode? By that I mean if a line reaches a specified column, automatically insert a newline at the word boundary closest to that column without going over. Vim has a setting called textwidth that does this that I like to use when editing Markdown. It doesn't seem like VSCode does, as far as I can tell. It just has ways to control softwrapping.


Solution

  • VSCode doesn't support this out of the box.

    Rewrap extension

    https://stkb.github.io/Rewrap/

    Previously called Auto wrap.

    It allows you to rewrap the block that your cursor is currently in by pressing Alt + Q.

    Rewrap also supports automatic wrapping (off by default).

    Rewrap requires no further settings, since it reads VSCode's settings to obtain the column at which to break.

    It supposedly works for various languages including JavaScript, Python, Markdown, latex, etc., and applies the rewrapping in a way that makes sense for the given context.