Steph8
Steph8

Reputation: 1583

Indent/format code in Visual Studio code on MAC

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!

Upvotes: 67

Views: 205789

Answers (17)

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

Upvotes: 5

Swati Sharma
Swati Sharma

Reputation: 41

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

Upvotes: 4

Simran
Simran

Reputation: 2810

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

Upvotes: 0

Hrishikesh Kadam
Hrishikesh Kadam

Reputation: 37342

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.

Upvotes: 5

dezmasterflex
dezmasterflex

Reputation: 17

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

Upvotes: 0

auspicious99
auspicious99

Reputation: 4311

(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

Upvotes: 18

Himanshu Suthar
Himanshu Suthar

Reputation: 487

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.

Upvotes: 6

Claudinei Ferreira
Claudinei Ferreira

Reputation: 514

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

Upvotes: 0

Douglas
Douglas

Reputation: 11

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

Upvotes: 1

sweetnandha cse
sweetnandha cse

Reputation: 961

Mac 16 M1 Pro

cmd + k + f working for me

Upvotes: 5

jsbisht
jsbisht

Reputation: 9649

The shortcut is: Alt + Shift + F

Upvotes: 63

panos.f
panos.f

Reputation: 54

On Visual Studio for Mac Version 8.7

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

Upvotes: 3

Max
Max

Reputation: 343

The shortcut is:

Option Shift F

Upvotes: 9

Tim Cuculic
Tim Cuculic

Reputation: 563

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

Upvotes: 37

Siddharth Sunchu
Siddharth Sunchu

Reputation: 1084

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

Upvotes: 22

Gregory
Gregory

Reputation: 111

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

Upvotes: 9

seN
seN

Reputation: 1095

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.

Upvotes: 60

Related Questions