» npm install @prettier/plugin-php
Core prettier does not support PHP1, and thus neither does the plugin for VSCode/VSCodium. Luckily the designers of prettier seems to have thought of this and implemented a plugin system2.
According to the prettier-vscode repo, all you need to do to use a plugin is to add it and prettier to your package.json3
So for php support your package.json would need to contain:
{
"devDependencies": {
"@prettier/plugin-php": "0.14.3",
"prettier": "2.0.5"
}
}
Prettier for HTML, CSS, and JavaScript files
change your settings.json
"editor.defaultFormatter": "esbenp.prettier-vscode",
// add this code
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
}
The settings use Intelephense as the formatter for PHP files and use Prettier as the formatter for all other files.
Now I use Shift + Alt + F to format the files like everybody else.
if you dont know ho to open setting.json lets see : I usually just press ctrl + , to get to settings and then click the "Open Settings (JSON)" icon that appears in the top right hand corner under the title bar Here's another option... VS Code: How to open settings.json file? How can I open Visual Studio Code's 'settings.json' file?