How to format file | project folder | all project files (using hot keys AND using menu) in Visual Studio Code?
If you're on Windows use Shift + Alt + F to make your code "pretty".
(This is similar to Ctrl + K + D in Visual Studio)
You will have to do this for each individual file though. I don't know of a way to format all files at once.
Shift
+Ctrl
+P
) for "Format Document". I'm on Windows so that's what I can speak to. What are you running @Sergii? –
Ladle Sierra
. –
Emmerich alt
key. –
Ladle Try with this hotkeys
Ctrl + Shift + i
@Sergii
Your question looks like you are looking for a way to format your entire code in VSCode. If this is the case, a VSCode extension like Prettier should meet the three requirements you've listed (file | project folder | all project files). Bear in mind though that formatting all project files is a bit unclear and you probably want to be specific about formatting all *.ts or all *.js files etc.
The below may be of help to you:
- Read about prettier because it provides ability to format entire code base
- Install prettier-vscode extension to your VSCode and enable settings that you want
- Alternatively, you can use prettier from the CLI, npm build script or via its API in build task - the choice is yours.
The one I found most useful is adding it as a git pre-commit hook for staged files.
I hope above points you in the right direction.
SOJ
In case you are not able to format your code with any of these commands it's maybe because you did not set up your formatter configuration
I recommend you to use Prettier (install from Extensions)
- open the command palette (CTRL + SHIFT + P - on windows)
- search for
prettier: Create Configuration File
- hit Enter and choose your project directory folder path
- if you can see a .prettierc file added into your directory, you must be able to use SHIFT + ALT + F to format your code
+1. also you are able to set your environment to automatically format your file at save.
You can do it writing this line in settings.json:
"editor.formatOnSave": true
Hint: Access it using the command palette again and writing settings.json, and select
Preference: Open Settings (JSON)
© 2022 - 2024 — McMap. All rights reserved.
Shift
+Alt
+F
works for me. – Emmerich