In VS Code preference, I set the Tab Width = 4 and Print Width = 120, but when I format, I can still see the tabSize being 2. Is there any other configuration that I need to do? Thanks.

  • Prettier does not appear to have an Apex formatter. Perhaps you may want to use uncrustify instead?
    – sfdcfox
    Commented May 29, 2020 at 3:16
  • Strange. Recent post from Salesforce is recommending Prettier for code formatting. developer.salesforce.com/blogs/2020/05/… Commented May 29, 2020 at 3:19
  • That makes more sense; there's a special plugin for prettier for Apex that has to be installed independently of prettier. Did you install it?
    – sfdcfox
    Commented May 29, 2020 at 3:22

1 Answer 1


After running the install command:

npm install --save-dev --save-exact prettier prettier-plugin-apex

Restart VS Code.

Then, go to View > Command Palette... and find the command "Prettier: Create Configuration File", and run it.

Finally, you can go to the .prettierrc file in your project's root folder, open it up, and set either the number of spaces to use or to use tabs.

I did not find a UI for editing this file, so I'm not entirely sure what configuration you may have been playing with.

  • That's cool!!, I would like to mention one thing if you were using Unscrustify previously, you need to uninstall or deactivate it or remove it from the default formatter, so prettier will format the apex code. Commented May 30, 2020 at 5:05
  • well, I ran the above command it worked well in my first project folder. When I switched to another project, and when I tried to format the apex code, it asked me to install the formatted, looks like the command did not apply for all of the workspaces. How can I enable it by default for all of my workspaces? Commented May 30, 2020 at 5:30
  • 1
    @rahulgawale Use the -g option on npm to install a plugin globally.
    – sfdcfox
    Commented May 30, 2020 at 16:46
  • thank you @sfdcfox Commented May 30, 2020 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .