关于Visual Studio代码:如何在VSCode中打开和关闭自动换行?

How to switch word wrap on and off in VSCode?

使用代码文件时,通常不需要较长的行来回绕。但是,对于.md文件,这实际上非常有用。但是,我似乎找不到启用自动换行的选项,因此将自动换行。

要进行复制,请打开将VSCode调整为一个足够小的窗口,然后在新文档中输入以下文本:

1
2
This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum.
A linebreak before this.

效果是这样的:

Example of missing word wrap

我试图使水平滚动条远离,使第1行环绕在窗口的右侧。

我做了一些事情来回答我自己的问题:

  • 搜索堆栈溢出:撰写本文时,结果为零;
  • 仔细浏览VSCode菜单:找不到它;
  • 将命令选项板与" wrap"一起使用:不提供匹配的命令。

也许这是不可能的,我需要提出功能请求?还是我错过了什么?

请注意,我希望能够快速打开和关闭它。例如,@ PanagiotisKanavos在评论中提到了此解决方案以更改设置中的换行行为,但是我正在寻找一种快速的命令或菜单选项来执行此操作(非常类似于Notepad ++和Sublime Text 2具备的功能)。


从v1.0开始,您可以切换自动换行:

  • 使用新命令editor.action.toggleWordWrap,或
  • View菜单("视图">"切换自动换行"),或
  • 使用ALT + Z键盘快捷键(对于Mac: + Z)。

也可以通过以下设置进行控制:

  • editor.wordWrap
  • editor.wordWrapColumn
  • editor.wrappingIndent


转到文件>首选项>用户设置。

它将自动打开默认设置和settings.json。只需将以下内容添加到settings.json文件中并保存。这将覆盖默认设置。

1
2
// Place your settings in this file to overwrite the default settings
{"editor.wrappingColumn": 0 }

Screenshot of settings being edited.


从版本0.3.0开始,包装已放入命令面板中。您可以使用Toggle Word WrapALT + Z激活它。


不推荐使用wrappingColumn,而推荐使用wordWrap

将此行添加到settings.json以默认情况下将wordWrap设置为on

1
"editor.wordWrap":"on"

或打开用户设置:

Mac: +

Windows:Ctrl +

然后搜索" wordWrap"或在"常用"设置中滚动以找到它并选择"打开"

enter image description here


来不及回答,但要供将来的访客使用。检查此屏幕截图。希望能帮助到你

enter image description here


从1.9开始,可以为自动换行设置(或任何设置)选择特定的语言。您可以在以下命令面板中找到它:

首选项:配置特定于语言的设置...

它将带您进入所选语言的" settings.json",其中可能包括:

1
2
3
4
"[markdown]": {
 "editor.wordWrapColumn": 100,
 "editor.wordWrap":"wordWrapColumn"
},


不知道何时添加它,但是我正在使用v0.10.8,而ALT + Z是用于打开和关闭自动换行的键盘快捷键。这满足了"能够快速打开和关闭它"的要求。

关闭VS Code后,该设置不会保留。要保持不变,您需要通过Radha使用settings.json文件的答案进行设置...

1
2
// Place your settings in this file to overwrite the default settings
{"editor.wrappingColumn": 0 }


进入"首选项"选项卡,然后搜索为"自动换行"。以下gif也很有帮助。

enter image description here


自动换行设置重新设计

以下是新的自动换行选项:

1
2
3
4
editor.wordWrap:"off" - Lines will never wrap.
editor.wordWrap:"on" - Lines will wrap at viewport width.
editor.wordWrap:"wordWrapColumn" - Lines will wrap at the value of editor.wordWrapColumn.
editor.wordWrap:"bounded"

线条将以最小视口宽度和editor.wordWrapColumn的值进行换行。


  • Windows:control+shift + press the key"P",现在在命令行中键入Toggle Word Wrap,然后按enter
  • MAC:command+shift + press the key"P",现在在命令行中键入Toggle Word Wrap,然后按enter

  • Mac:代码->首选项->设置->在搜索设置中输入自动换行->更改编辑器:自动换行从关闭到打开。

  • Windows:文件->首选项->设置->在搜索设置中输入自动换行->更改编辑器:自动换行从关闭到打开。


如果要永久使用自动换行,请转到preference>> settings并更改editor.wordWrap:"on"。这将始终适用。
但是,我们通常会不断更改检查代码的偏好。因此,我使用ALT+z键包装文件的书面代码,或者可以转到View >> Toggle Word Wrap。这适用于您不总是想要的时候。再次ALT+z撤消wordWrap(将在一行中显示整行)。


如果要在vs代码编辑器中使用文本自动换行,则必须按Alt + Z按钮进行文本自动换行。它的自动换行是切换文本自动换行