如何在VSCode中自动硬换行?我的意思是,如果一行到达了指定的列,自动在最接近该列的单词边界处插入换行符,而不会越过。Vim有一个叫做textwidth的设置,我喜欢在编辑Markdown时使用它。据我所知,VSCode并没有这样做。它只是有办法控制软件。
当前回答
截至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
可以使用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)
你不需要任何扩展就可以做到这一点。你只需要使用两个正则表达式搜索和替换。
通过将要重新换行的行移动到单独的文件中来隔离它们。 把所有的线连接成一条线。例如,ctrl+h, "\n" ==> " "。注意:确保regex已启用(点星号图标) 将一条线分割成多条线。例如,ctrl+h, "(.{100})==> "$1\n"。注意圆括号后面的空格。 将这些行复制回原始文件。
这种技术有很多变种。例如,您可以使用逗号代替空格"(.{100})," ==> "$1,\n"。您可以使用Find in Selection alt+L而不是使用临时文件。
如果有人在运行时遇到问题,可能需要禁用辅助功能支持/屏幕阅读器。转到首选项>>文本编辑器>>可访问性支持,并将其关闭。
目前在GitHub上的VS代码问题跟踪器中有一个开放的请求,你可以在这里找到它
推荐文章
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 使用正则表达式搜索和替换Visual Studio代码
- 如何缩进/格式选择的代码在Visual Studio代码?
- 如何禁用预览文件与点击在vs代码?
- Visual Studio代码更改文件资源管理器托盘的字体大小?
- 如何防止Visual Studio Code总是重新打开以前的文件或文件夹?
- VSCode单引号到双引号自动替换
- 如何删除Visual Studio代码中的重复行?
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。VSCode中的json
- 如何格式化Visual Studio Code项目中的所有文件?
- Pylint在Visual Studio代码中“未解决的导入”错误
- 如何在VS Code中默认打开文本换行
- 在Visual Studio代码中更改突出显示文本的颜色
- Visual studio代码-键盘快捷键-全部展开/折叠