How to indent/format a selection of code in VSCode with ctrl+shift+f

雨燕双飞 提交于 2019-11-28 14:49:42

问题


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.


回答1:


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.



回答2:


  • 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 .




回答3:


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

Option + Shift + F



回答4:


On MacOS visual studio code version 1.36.1 (2019)

To auto-format the selection, use ⌘K ⌘F (the trick is that this is to be done in sequence, ⌘K first, followed by ⌘F).

To just indent (shift right) without auto-formatting, use ⌘]

As in Keyboard Shortcuts (⌘K ⌘S, or from the menu as shown below)



来源:https://stackoverflow.com/questions/40492960/how-to-indent-format-a-selection-of-code-in-vscode-with-ctrlshiftf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!