You can toggle word wrap for the VS Code session with Alt + Z (macOS: Option (or Alt) ⌥ + Z ) or select View > Word Wrap from Menu.
You can toggle word wrap for the VS Code session by pressing a key combination. On Windows or Linux, simply press Alt+Z. On MacOS, you can also press Option ⌥ + Z. Alternatively, one can enable/disable word wrapping by selecting View > Word Wrap from the Menu.
VSCode doesn't support this out of the box. But you can install the Rewrap
extension, which allows you to format the block that your cursor is currently in by pressing Alt + Q.
Rewrap
requires no further settings, since it reads VSCode's settings to obtain the column at which to break.
Rewrap
also supports automatic wrapping (off by default): https://github.com/stkb/Rewrap/wiki/Auto-wrap
Unfortunately, VSCode doesn't have this feature yet. But, we still can make it to be as close as vim automatic word wrapping beautiful feature.
We need to setup soft word wrap feature in VSCode.
Code => Preferences => Settings
.Add these 3 lines of editor settings.
"editor.wordWrap": "wordWrapColumn",
"editor.wrappingIndent": "same",
"editor.wordWrapColumn": n
Don't forget to change (n) with your preferred length of columns line. For me, I feel more comfortable to set it to 60.
Save this setting.
The main purpose of this first step is to make us feel more comfortable when we're typing because we don't need to manually type Enter and see a long line of text.
We need to install Vim emulation for VSCode and set vim textwidth
.
Code => Preferences => Settings
.Add this line of vim setting.
"vim.textwidth": n,
Don't forget to change (n) with your preferred length of columns line. For me, I will set this to be the same with (n) in the first step.
Save this setting.
When you finish to write your whole document, you can format it to be hard wrap lines using this way.
Now VSCode support auto wrapping out of the box.
Settings --> Text Editor --> Last 3 options (as on today) is for autowrapping.
By default Word Wrap is off.
Hard Wrap Comments
Use the Rewrap extension.
Soft Wrap Code
Add the following setting (replace column width with your preference): "editor.wordWrapColumn": 100
Then add either "editor.wordWrap": "wordWrapColumn"
(wraps at the column) or "editor.wordWrap": "bounded"
(wraps at either the column or the viewport).
Hard Wrap Comments and Soft Wrap Code
Unfortunately the extension and VSCode settings do not play nicely.
Feel free to upvote this feature request.
As of 2020 and if you're using the Prettier - Code formatter
plugin:
Go to Plugins -> Find Prettier -> Cog -> Extension Settings -> Prettier: Print Width Fit code within this line limit
and set to whatever you want. By default it's 80.
When you save the file, Prettier will format automatically.
There is currently an Open request for this in the VS Code Issue tracker on GitHub, You Can Find It Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With