Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Code in Visual Studio Code not working on Mac OS X (El Capitan)

Update:

Not sure what happened to my Visual Studio Code installation, but removing and re-installing the application (via homebrew) fixed the problem. Shift - Option - F once again formats code!


I'm struggling to format code in Visual Studio Code on MAC OSX El Capitan.

For some reason the default key binding ('Shift + Option + F') does not work. I also no longer have the option to format code via the 'Command + Shift + P', and entering '>format code'. In fact, '>format code' isn't even an option in the list anymore.

This used to work, but I am not sure what changed.

'Shift + Option + F' does do something though, it makes a ' ̰' character appear that results in some weird cursor behaviour (not sure how else to describe it) when moving over characters adjacent to the ' ̰' character.

Additional information:

  • I'm creating an Ember.js (v2.3.0) application
  • I've tried formatting *.js, *.hbs and *.json files, but it doesn't work in any of these
like image 881
De Ville Weppenaar Avatar asked Feb 13 '16 09:02

De Ville Weppenaar


People also ask

How do I get beautify code in Visual Studio Mac?

VSCode – Code Formatting Shortcuts The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations: On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.

How do I fix Visual Studio formatting code?

The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.


2 Answers

I came from Windows to Mac as a newbie, expecting the most basic things like code formatting would work with Shift+ALt+F as it does on Windows. But naturally, it didn't. The problem was, Keyboard - Input Source (Default in India - [ABC - India]) doesn't capture Shift+Alt+F, which was evident in the "Command Palette: Developer: Toggle Keyboard Shortcuts Troubleshooting"

Solution:

  • System Preferences -> Keyboard -> Input Sources (tab)
  • I had ABC - India (defaulted), needed to remove it and added U.S. International - PC

Screenshot of the keyboard settings on Mac

like image 150
Manish Avatar answered Sep 18 '22 01:09

Manish


It's happening from time to time in my mac and if I just restart VScode it works again. Give it a try before reinstalling it the next time

like image 33
Unseen Avatar answered Sep 21 '22 01:09

Unseen