Any clues on why my VS Code "Format Code" command doesn't work? I used Shift+Ctrl+P and entered Format Code or used the shortcut Shift + Alt + F. None seem to be working. Any clue?
- Which file type / language do you want to format? Maybe code formatting is not supported for that language.Wosi– Wosi2016-09-29 20:42:59 +00:00Commented Sep 29, 2016 at 20:42
- Just plain html. The file is saved as such and HTML is showing at the info bar. I was expecting that this command would format elements, breaking lines and indenting.Marcos Silva– Marcos Silva2016-09-30 14:53:57 +00:00Commented Sep 30, 2016 at 14:53
- @MarcosSilva i think you should change the accepted answer mark to one which is relevant so that people can find it on top. I have added one ans that you can check in the thread.Shubham kumar– Shubham kumar2021-06-26 13:28:56 +00:00Commented Jun 26, 2021 at 13:28
- Thank you @Shubhamkumar. For me, this issue was resolved when I first reported it and seemed to be related to a bug. I'm not sure if the solutions provided more recently applied to the original issue. But they may be valid for others.Marcos Silva– Marcos Silva2021-06-27 14:10:17 +00:00Commented Jun 27, 2021 at 14:10
16 Answers
I guess you are asking for MacOs because by default shortcut for code formatting is different for different Os. Now there might be an issue with the keyboard layout.
For example Option+Shift+F does not work in ABC-Indian layout, you need to change that. Go to System-prefrences->Keyboard->Input Sources-> Add layout "ABC" and delete the old one.
1 Comment
For me, CTRL SHIFT i worked on Ubuntu 20.04
3 Comments
Shift + Alt + I and expect cursors at the end of the lines starting from the current line. However, first, you've to select the paragraph where you want the cursors and then press Shift + Alt + I.You need to set the default formatter in your VS Code.
Click Cmd+Shift+P, and choose "Format Document With..."
Then, instead of choosing a formatter, choose "Configure Default Formatter..."
And then choose your default formatter that works for you
It will now work and format the document when you click SHIFT+OPTION+F (or Shift+Alt+F in Windows). My default formatter was configured to Prettier ESlint instead of Prettier - Code Formatter and it didn't work. The shortcut worked only after changing the default formatter to Prettier - Code Formatter.
You can install it here: https://prettier.io/docs/en/install.html
Comments
i'm having the same issue - it's looks like a bug.
See:
Comments
The bug is partially fixed in v1.6.0.
You may still face this issue as the patch is not for all keyboard layouts. Switching keyboard layout to English(US) solved the problem for me.
The issue is open on github.
1 Comment
I had the Same Issue and Found a working solution.
- Right click on the file which you want to format.
- Select "Format With" option.
- Choose Last option i.e 'Select Default Formatter'
- Then select you preferred Formatter option. Voila ! you are all Done. it should be working fine again on ALT+SHIFT+F.
Note : i tried all way by setting default to reinstall formatter and still it didn't work until this above solution. Thanks me Later !!
Comments
I faced the same issue (on ubuntu 18 - windows didn't seem to have this issue).
You can resolve this by changing the keybinding.
Go to File -> Preferences -> Keyboard shortcuts
Search for Format Document to find out which keybinding is currently able to format your code.
You can choose to continue with the default keybinding or change it by clicking on the edit icon on the left of the command you're interested in changing.
In this case, you would simply hit Alt + Shift + F and that's it.
Comments
For me it was an extension that greedily used that shortcut
- Go to Code > Preferences > Keyboard shortcuts
- Find the shortcut that doesn't work
- Right-click > 'Show same keybindings'
- Right click to remove any that are obviously clashing that you don't need For me the issue was with command + shift + f which clashed with an extension that came with the Vue Volar extension pack. A different issue but it may solve the original issue
Comments
If there is an error in the code, the shortcut key will not work.
1 Comment
There is some default keybinding, due to which "option + some key" results in adding some sign like a ~ or ^.
In my condition I was able to format using command palette or right click on document and then selecting Format document , but not by using keyboard.
Just change the keyboard shortcuts( code > settings> keyboard shortcuts), and then search format document , on left side on hovering a pencil(edit button) clickon that and then change the keys to. command + shift + f instead of option + shift+ f and hit enter.
Now, you will be able to format document using keys-> cmd+ shift + f
1 Comment
Newer answer to an older question, but it might be useful for someone who's looking for this subject: In VS Code (and Azure Data Studio) for your Keyboard Shortcuts, you can edit the expression for the When condition.
This takes into account when your Shortcut keybinding should apply.
There could be something wrong with the expression mentioned there, or the situation when you press your combo might not apply exactly as you would think.
For mor info on how the When clause should be built and which contexts are available etc, see here.





