如何在VSCode中自动硬换行?我的意思是,如果一行到达了指定的列,自动在最接近该列的单词边界处插入换行符,而不会越过。Vim有一个叫做textwidth的设置,我喜欢在编辑Markdown时使用它。据我所知,VSCode并没有这样做。它只是有办法控制软件。


当前回答

可以使用C_Cpp中的ColumnLimit成员轻松设置列限制。设置中的clang_format_fallbackStyle。json(你必须安装微软C/ c++扩展)

"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, IndentWidth: 4, ColumnLimit: 80 }",

然后你可以使用Shift + Alt + F来格式化文件

在这个格式特性中,您可以更改许多选项

"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 80, AccessModifierOffset: -4 }",

Name of the predefined style used as a fallback in case clang-format is invoked with style file but the .clang-format file is not found. Possible values are Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU, none, or use {key: value, ...} to set specific parameters. For example, the Visual Studio style is similar to: { BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }

之前

void Proc::Memory::getSramOff(const char* mem_name, uint dataSize, uint addrBits, uint& noOfBytes, uint& sram_off)

void Proc::Memory::getSramOff(const char* mem_name, uint dataSize,
    uint addrBits, uint& noOfBytes, uint& sram_off)

其他回答

可以使用C_Cpp中的ColumnLimit成员轻松设置列限制。设置中的clang_format_fallbackStyle。json(你必须安装微软C/ c++扩展)

"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, IndentWidth: 4, ColumnLimit: 80 }",

然后你可以使用Shift + Alt + F来格式化文件

在这个格式特性中,您可以更改许多选项

"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 80, AccessModifierOffset: -4 }",

Name of the predefined style used as a fallback in case clang-format is invoked with style file but the .clang-format file is not found. Possible values are Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU, none, or use {key: value, ...} to set specific parameters. For example, the Visual Studio style is similar to: { BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }

之前

void Proc::Memory::getSramOff(const char* mem_name, uint dataSize, uint addrBits, uint& noOfBytes, uint& sram_off)

void Proc::Memory::getSramOff(const char* mem_name, uint dataSize,
    uint addrBits, uint& noOfBytes, uint& sram_off)

现在VSCode支持自动“软”包装。

设置->文本编辑器->最后3个选项(今天)是自动换行。

换行(控制行如何换行) 换行列(控制编辑器的换行列) 换行缩进(控制换行行缩进)

默认情况下,自动换行是关闭的。

截至2020年,如果你使用的是Prettier - Code formatter插件:

转到插件-> Find Prettier -> Cog -> Extension Settings -> Prettier:在此行限制内打印宽度适合代码,并设置为任何您想要的。默认值是80。

当你保存文件时,pretty会自动格式化。

VSCode不支持开箱即用。但是您可以安装Rewrap扩展,它允许您通过按Alt + Q来格式化光标当前所在的块。

Rewrap不需要进一步的设置,因为它读取VSCode的设置来获得要中断的列。

Rewrap还支持自动包装(默认关闭):https://github.com/stkb/Rewrap/wiki/Auto-wrap

其中大多数都不适合我,但我找到了扩展Vsctoix,它可以。

我们从第80列开始换行:

Mechanisms such as a “windfall clause” help distribute riches within particular 
futures. But for a windfall clause to be useful, many conjunctive assumptions 
have to be true. We present a new method to borrow against potential future 
windfalls today, when they have greater marginal use. The method also increases 
the probability and thus the expected value of the windfalls.

然后执行“IX: Join Lines”(无参数):

Mechanisms such as a “windfall clause” help distribute riches within particular futures. But for a windfall clause to be useful, many conjunctive assumptions have to be true. We present a new method to borrow against potential future windfalls today, when they have greater marginal use. The method also increases the probability and thus the expected value of the windfalls.

然后参数为100的“IX: Break Line At”:

Mechanisms such as a “windfall clause” help distribute riches within particular futures. But for a 
windfall clause to be useful, many conjunctive assumptions have to be true. We present a new method 
to borrow against potential future windfalls today, when they have greater marginal use. The method 
also increases the probability and thus the expected value of the windfalls.

如果它尊重换行符并同时执行这两个步骤,那就太棒了,但到目前为止,它是唯一适合我的扩展-除了我还没有尝试过vim模拟。