Format a VS Code document or only the selected code
Shift-Option-F formats the document; Command-K then Command-F formats the selection when an appropriate formatter is available.
- Scope
- Visual Studio Code · Current vendor documentation checked 3 November 2026; no running-app compatibility test is claimed.
- Keyboard and customization
- Documented Mac defaults; punctuation and function keys depend on keyboard layout and hardware.. User bindings, app versions, focused controls and installed extensions can change a command. Inspect the active app menu or its shortcut editor when a listed combination differs.
- Review basis
- Documentation reviewed 2026-11-03 by Codex — primary-documentation and editorial review; no hands-on runtime test. These bindings were not tested in a running app for this guide.
Choose the scope before formatting
Whole-document formatting can change lines outside the area you were editing. Selection formatting narrows the intended scope, but still depends on the formatter and language support. Decide which result you need before running the command, especially in a repository where formatting changes can obscure a small functional edit.
Check which formatter owns the file
A missing formatter, multiple available formatters or project-specific configuration can explain an unexpected result. Inspect the editor’s formatter choice rather than assuming the key combination guarantees a particular style. Extension and workspace settings can affect both the available formatting actions and their output.
Review the diff after the action
Formatting is an edit, so check the resulting changes before saving or committing them. Confirm that the expected scope was respected and that unrelated lines did not change unnecessarily. Practise on a disposable file if you are evaluating a new formatter or changing the project’s formatting configuration.
Review the resulting diff
Format a disposable example first, then inspect the diff before accepting a project-wide style change. A formatter can rearrange whitespace across many lines without changing the intended program logic. Confirm which formatter and project configuration produced the result before saving.
Documented commands for this workflow
Scroll the table sideways to see every column.
Sources and corrections
- Default keyboard shortcuts — Visual Studio Code — checked 2026-11-03
- Basic editing — Visual Studio Code — checked 2026-11-03
Found a mismatch? Email pashaseenainc@gmail.com with your app version, macOS version, keyboard layout and the command. Please leave personal document names out.
Keep going
Right there when you need it.
Keep a compact shortcut reference in your Mac’s menu bar.
Explore the native Mac app