De Ville Weppenaar
De Ville Weppenaar

Reputation: 231

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:

Upvotes: 22

Views: 13676

Answers (8)

Rohan Sapkal
Rohan Sapkal

Reputation: 41

on mac keyboard type US International - PC screws up few characters like the usual shift + 6 "^" is replaced with "ˆ" , i set it to just US from ABC India and it worked fine

Upvotes: 3

Shashank Rawat
Shashank Rawat

Reputation: 1571

Solution

  1. Go to the system settings then go to the keyboard section.

If your input sources are other than ABC (eg ABC - India) that might be the source of this issue.

Screenshot 1

  1. Go to edit Input Sources and add a new Input source.

Screenshot 2

  1. Add ABC keyboard Input source.

Screenshot 3

  1. Now remove ABC - India input source.

Screenshot 4

Upvotes: 21

Sourav Kumar
Sourav Kumar

Reputation: 11

If the 'Format Document' shortcut(option+shift+F) is not working on your MAC you can try right-clicking and then using the format document option.

Still, it is mostly because your text input is set to a different keyboard layout such as British, Indian, etc. You need to change your default to U.S.

To change your text input goes to your mac setting>search keyboard>Text Input>InputSources>Edit>then use + sign to add US layout and use - to remove other ones.

Hope it works fine after that.

Upvotes: 1

Manish
Manish

Reputation: 625

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

Upvotes: 58

Marcos Silva
Marcos Silva

Reputation: 2019

I had the same issue and realized that there was a fixed for that. VS Code repo has a closed issue for that and this may explain why your issue was fixed after reinstalling.

This is the link for the question on the VS Code repo:

https://github.com/Microsoft/vscode/issues/11810

Upvotes: 1

Unseen
Unseen

Reputation: 287

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

Upvotes: 1

iaarnio
iaarnio

Reputation: 429

I had the same problem. January 2016 Visual Studio Code release had preliminary support for Salsa. In order to use that you had to install Typescript 1.8 and add typescript.tsdk setting like:

// Specifies the folder path containing the tsserver and lib*.d.ts files to use. "typescript.tsdk": "./node_modules/typescript/lib"

February 2016 Visual Studio Code release does not need that anymore as Salsa is default anyway. Removing typescript.tsdk setting enabled code format functionality again for me.

Upvotes: 0

Avin Zarlez
Avin Zarlez

Reputation: 1682

I am glad you were able to solve your own problem!

Often a simple reinstall can fix a lot of odd issues with various programs. Depending on what version you were on, updates can also fix bugs that might have caused the issue.

Upvotes: 0

Related Questions