如何使用 Ctrl + Shift + F 在 Visual Studio Code 中缩进/格式化所选代码

问题描述:

我想在 Visual Studio Code 中缩进特定的代码部分.

I want to indent a specific section of code in Visual Studio Code.

我阅读了你如何在 Visual Studio Code 中格式化代码? 提供了缩进的快捷方式整个代码,但在选择特定代码部分时不起作用.

I read How do you format code in Visual Studio Code? that gives shortcuts to indent the whole code, but it doesn't work when selecting a specific section of code.

在选择代码中的某些行后,我尝试了 Ctrl + Shift + F,但整个文件都缩进了.我在 Windows 上使用 Visual Studio Code Insider 1.8.0.我该怎么做?

I tried Ctrl + Shift + F after selecting some line in my code, but the whole file is indented. I'm on Windows with Visual Studio Code Insider 1.8.0. How can I do it?

我想缩进 Visual Studio Code 中的特定代码部分:

I want to indent a specific section of code in Visual Studio Code:

  • 选择要缩进的行,然后
  • 使用 Ctrl + ] 来缩进它们.
    • Select the lines you want to indent, and
    • use Ctrl + ] to indent them.
    • 如果您想格式化一个部分(而不是缩进):

      If you want to format a section (instead of indent it):

      • 选择要格式化的行,
      • 使用 Ctrl + KCtrl + F 来格式化它们.
      • Select the lines you want to format,
      • use Ctrl + K, Ctrl + F to format them.