How to indent/format a selection of code in Visual Studio Code with Ctrl + Shift + F

Damien Leroux picture Damien Leroux · Nov 8, 2016 · Viewed 183.2k times · Source

I want to indent a specific section of code in 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.

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?

Answer

Shaun Luttin picture Shaun Luttin · Nov 8, 2016

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

  • Select the lines you want to indent, and
  • 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.