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.
相关问题
- Extended message for commit via Visual Studio Code
- Where are Automatic Type Acquisition typescript de
- Typescript: Why doesn't visual studio code rep
- .NET Core 3.1 CreateHostBuilder Cannot parse JSON
- How to get VS Code debug data like breakpoints, st
相关文章
- Visual Studio Code, MAC OS X, OmniSharp server is
- Omnisharp in VS Code produces a lot of warnings ab
- Visual Studio Code command for “repeat last comman
- VSCode remove warnings from problems tab
- Configure a TypeScript project with common depende
- Visual Studio Code disabling Normal, Edit and Visu
- Vscode: error TS2307: Cannot find module 'vsco
- How to customize context menu in Visual Studio Cod
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.
First Step
We need to setup soft word wrap feature in VSCode.
Code => Preferences => Settings
.Add these 3 lines of editor settings.
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.
Second Step
We need to install Vim emulation for VSCode and set
vim textwidth
.Code => Preferences => Settings
.Add this line of vim setting.
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.
Actual Use
When you finish to write your whole document, you can format it to be hard wrap lines using this way.
There is currently an Open request for this in the VS Code Issue tracker on GitHub, You Can Find It Here
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.
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.While
Rewrap
is not automatic (you need to press the keyboard shortcut whenever you want to format), automatic hard wrapping seems to be a feature that will come in the nextRewrap
release: https://github.com/stkb/Rewrap/issues/45