Reputation: 2019
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?
Upvotes: 39
Views: 89010
Reputation: 779
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.
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 548
For me it was an extension that greedily used that shortcut
Upvotes: 1
Reputation: 11
Maybe you haven't install package autopep8.
You can use the command to install it, it works for me.
conda install autopep8
or
pip install autopep8
Upvotes: 0
Reputation: 73
Install vs-code extension called "Prettier - Code formatter". Then set it as default formatter. The popup should guide you for this. The Option+Shift+F in Mac should work as expected to do auto formatting.
Upvotes: 0
Reputation: 812
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.
Upvotes: 64
Reputation: 61
I also faced the same problem. My issue was that in my VScode's settings.json (ctrl + ,), I had multiple 'defaultFormatter' selected. I commented out one of them and it started working.
Upvotes: 0
Reputation: 4903
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.
Upvotes: 2
Reputation: 2755
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
Upvotes: 15
Reputation: 31
I had the Same Issue and Found a working solution.
Note : i tried all way by setting default to reinstall formatter and still it didn't work until this above solution. Thanks me Later !!
Upvotes: 3
Reputation: 41
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.
Upvotes: 3
Reputation: 49
If you have an error in your code, the formatting will not allow you to change the layout. Fix any bugs you have (if you have any of course) then try shift + alt + f.
Upvotes: 5
Reputation: 33545
Make sure you changed your language to the type of file. (Ctrl+K,M or Ctrl+Shift+P -> Change Language Mode)
Upvotes: 0
Reputation: 949
i'm having the same issue - it's looks like a bug.
See:
Upvotes: 6