How to indent/format a selection of code in VSCode

2019-01-31 07:49发布

I want to indent a specific section of code in VSCode

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

I tried ctrl+shift+F after selecting some line in my code but the whole file is indented. I'm on Windows with VSCode Insider 1.8.0. Any help is appreciated.

3条回答
一纸荒年 Trace。
2楼-- · 2019-01-31 08:02

I want to indent a specific section of code in VSCode:

  • Select the lines you want to indent,
  • use Ctrl + ] to indent them.

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

  • Select the lines you want to format,
  • use Ctrl + K, Ctrl + F to format them.
查看更多
混吃等死
3楼-- · 2019-01-31 08:04
  • you can also indent a whole section by selecting it and clicking TAB
  • and also indent backward using Shift+TAB

and of course for auto indentation and formatting, following the language your using you can see which good extension do the good job, and which formatters to install or which parameters settings to enable or set. Each language and it's available tools. Just make sure to read well the documentation of the extension, to install and set all what it need. Up to now indentation problem bother me with python when copy pasting a block of code, if that's the case here how you solve that https://stackoverflow.com/a/46899704/7668448 .

查看更多
太酷不给撩
4楼-- · 2019-01-31 08:20

In OSx "Document Format" , Select all lines that you need format

Option + Shift + F
查看更多
登录 后发表回答