61

i'm trying to indent my code in visual studio code. I searched and i found that ctrl + F + K should be work, but it doesn't. I tried cmd + k + f too, but it still not working. I hope you can help me!

3
  • Close, but it is not exactly cmd + k + f (not all 3 keys at the same time), see my answer below for the exact combination. Commented Jun 4, 2020 at 10:11
  • In VS4Mac 2019, there are three shortcuts configurations: VS for Mac (native), VS for Windows and VS Code. It prompts to select one of three scheme right after the installation. That is why the answers below are different and confusing; as each one is covering different scheme, without specifying which one. VS for Mac's native shortcut to format document is mentioned in Tim Cuculic's answer: Control + i, but if you had VS for Windows scheme selected, it won't work (then I think the shortcut is Control + Shift + F). Commented Nov 25, 2020 at 23:11
  • Thanks for pointing that out. It looks like the question is asking for VS Code, though. VS Code comes as a standalone product where there isn't a choice of shortcut configs to use. Commented Jun 3, 2021 at 18:14

17 Answers 17

60

The shortcut is: Alt + Shift + F

0
57

Updated December 21, 2017: as pointed out by Fabio, on mac it should be: + ]

On Windows: indent control is ctrl + ]

A good way to find commands is by navigating to: Code -> Preferences -> Keyboard Shortcuts

Also, the Visual Studio Code team provided those handy shortcut pdfs:

Another helpful command to achieve this might be: shift + option + f which is auto format.

5
  • 3
    On Mac it will be ] (not control)
    – Fabio
    Commented Dec 20, 2017 at 23:29
  • 7
    This only indents the code, it doesn't actually format it. option+shift+F doesn't do it either
    – Pablo
    Commented Apr 6, 2018 at 19:32
  • 8
    on mac it's option-shift-F
    – Sam Joseph
    Commented Jul 24, 2018 at 9:33
  • m1 mac seems denying this option-shift-f. does anyone knows how to fix that? Commented Dec 24, 2021 at 3:19
  • 4
    There is no key ] on my Macbook (16" M1 Pro, Monterey 12.3). But Shift+Option+F worked.
    – Azimuth
    Commented Mar 22, 2022 at 14:03
36

The shortcut to format code on Visual Studio for Mac Community Edition is Ctrl + i

3
  • 4
    As of Feb 2021 this does not appear to work, option + shift + f works
    – Mark
    Commented Feb 23, 2021 at 18:30
  • 2
    When I press Ctrl + i, nothing happens. Commented May 20, 2022 at 2:01
  • 3
    it works for me on VS Mac 2022
    – stanimirsp
    Commented May 21, 2022 at 10:24
18

The shortcut to align code in MAC is : Option/ALT + Shift + F.

18

(edited on 4th Jan 2023: the answer below still remains the same, in version 1.74.2, Nov 2022)

For visual studio code version 1.36.1 (2019)

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

auto-format selection or document

To just indent (shift right) without auto-formatting, i.e., blindly indent, use ⌘]

indent options

As indicated in Visual Studio Code's Keyboard Shortcuts (⌘K ⌘S, or from the menu as shown below)

keyboard shortcuts

4
  • 1
    I had to install a formatter, but after that, this worked. Commented Sep 21, 2023 at 5:36
  • @JaydenLawson thanks for sharing about this. what version of Visual Studio Code were you using? and how did you install the formatter? Commented Sep 22, 2023 at 12:25
  • 1
    1.82.2 (Universal) on Mac. Formatter: went to Code > Settings > Extensions, and installed the "PHP Intelephense" extension. Commented Sep 24, 2023 at 1:38
  • 1
    @JaydenLawson that is the real answer - without the extension, the keyboard commands are essentially useless
    – J. Gwinner
    Commented Dec 1, 2023 at 0:05
9

Visual Studio for Mac Community Edition v 7.5.4 code format is: ^ I

6

The shortcut is:

Option Shift F
0
5

Mac 16 M1 Pro

cmd + k + f working for me

5

cmd + A + cmd + K + cmd + F

this worked for me.

All I do is to hold "cmd" and then press A, K, and F one by one.

1
  • 1
    This worked for me, pressing above combination in sequence as mentioned above. Thanks @Himanshu Commented Mar 1, 2023 at 11:44
3

On Visual Studio for Mac Version 8.7

Select the code and go Edit -> Format -> Format Document Edit -> Format -> Format Document

3

For me, the Input Source was English India.
So, Option + Shift + F resulted in showing  ̰

After changing the Input Source to English I was able to format the code using the above shortcut.

2

Cmd + K and then Cmd + F these two chord are required

2

This worked for me on Mac OS. (alt + shift + F)

1

Only Ctrl + I for me worked. Everything else hasn't worked.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 30, 2022 at 3:11
0

Fix Formatting in Visual Studio for MAC 2019: Control + I Source here

0

You can always redefine the shortcut via the preferences > Keyboard Shortcuts: Mine was set to ^|, which did not work. So I changed it to shift + option + f (since this shortcut only printed Ï)

Hope this helps ;).

0

By below steps you can update your preference (2024)

  • Click on code > settings > Keyboard Shortcuts

Screenshot for setting

  • On the search box write the format and add key binding for the "Format Document" row

Screenshot for format

Not the answer you're looking for? Browse other questions tagged or ask your own question.