Align Code in VS Code: Shortcuts, Extensions, and Formatting Methods
Updated Jul 2026
Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.
- Use built-in format commands for basic line indentation
- Master multi-cursors for quick manual column alignment
- Install specialized extensions like Better Align for equal-sign tidying
- Configure settings.json to prevent formatters from stripping extra spaces
Align Code in VS Code: Shortcuts & Methods for Clean Formatting
To align code in VS Code, you can trigger auto-formatting with `Shift+Alt+F` (`Shift+Option+F` on macOS), use multi-cursor editing (`Alt+Click` or `Ctrl+Alt+Up/Down`), or install column-alignment extensions like Better Align. These techniques help keep variable assignments, object keys, and trailing comments neatly lined up across multiple rows.
Understanding Code Alignment in VS Code
Code alignment in VS Code involves arranging variables, assignment operators, object properties, or comments into uniform vertical columns. While basic auto-formatting cleans up indentation at the start of a line, vertical alignment organizes tokens within lines to make complex multi-line blocks readable and far easier to scan during code reviews.
Standard indentation pushes your code to the correct depth based on scope, such as inside a function or loop. Vertical alignment, however, targets matching characters across consecutive lines. For example, lining up equal signs in a block of variable declarations creates visual consistency that makes spotting unassigned variables or typos much easier.
While some developers prefer strict column alignment, others lean on automated tools that collapse extra spacing. Knowing how VS Code handles both styles lets you maintain team standards without fighting your editor.
Why Vertical Alignment Matters in Codebases
Vertical code alignment reduces cognitive fatigue by establishing predictable visual anchors across multiple lines. When equal signs, array elements, or dictionary keys line up vertically, your eyes skim structure faster, making typos, missing values, and logical inconsistencies immediately obvious during refactoring.
When working on large configuration files or long lists of constants, tabular layouts reduce visual noise. Instead of parsing jagged assignments, you can read keys down the left column and values down the right column. That said, manual vertical alignment can sometimes create larger git diffs if adding a long variable name forces re-indenting surrounding lines. Striking a balance between clean layout and clean git histories is key.
Native VS Code Methods and Shortcuts for Alignment

VS Code lacks a single native button for lining up equal signs across lines, but it provides powerful built-in formatting tools. Combining document formatting (`Shift+Alt+F`), block indentation shortcuts (`Ctrl+]`), and multi-cursor editing lets you manually construct clean alignment columns without installing third-party tools.
Before reaching for extensions, native tools handle most daily formatting needs. They work instantly across every language without extra configuration or external dependencies.
Formatting Documents and Selections
To format an entire file in VS Code, press `Shift+Alt+F` on Windows/Linux or `Shift+Option+F` on macOS. If you only want to adjust a specific snippet, highlight the block and hit `Ctrl+K Ctrl+F` (`Cmd+K Cmd+F` on Mac) to run `Format Selection` without touching the rest of your file.
These commands rely on your configured default formatter, such as the built-in TypeScript formatter, Python's autopep8, or Prettier. Running `Format Document` fixes inconsistent spacing around operators and corrects line indents, establishing a clean foundation before you do any manual alignment.
Multi-Cursor Editing for Manual Column Alignment
Multi-cursor editing gives you precise control over mid-line alignment across multiple rows simultaneously. Hold `Alt` and click (`Option` on Mac) on each line, or press `Ctrl+Alt+Up/Down` (`Cmd+Option+Up/Down`), then press Space or Tab to align operators like equal signs or colons in one motion.
Here is how to use multi-cursors for column alignment step by step:
- Position your cursor right before the operator (like `=`) on the first line.
- Press `Ctrl+Alt+Down` (`Cmd+Option+Down` on macOS) to drop additional cursors down through the remaining lines.
- Use the Spacebar or Tab key to push all operators over together until they line up cleanly with the longest line.
- Press `Escape` to clear the extra cursors once you finish.
Top Extensions for Automatic Column Alignment
When manual multi-cursor editing becomes tedious, dedicated VS Code extensions automate column alignment instantly. Extensions like Alignment, Better Align, or Rewrap scan your selected code block and automatically align assignment operators, object parameters, and multi-line comments based on common delimiters.
Extensions save time when dealing with large blocks of assignments or complex nested objects. Instead of manually counting spaces, a single hotkey handles the layout for you.
Alignment / Better Align
The Better Align extension (and its predecessor, Alignment) lets you highlight a block of code and press `Alt+A` (or `Cmd+Alt+A` on Mac) to vertically align equal signs, colons, and assignment operators. It automatically calculates target column widths to produce clean, readable code blocks effortlessly.
Better Align inspects the highlighted selection, detects common assignment tokens (like `=`, `+=`, `:`, or `=>`), and inserts calculated spaces before each token. It automatically strips unnecessary spaces on repeat runs, keeping line lengths clean without messing up surrounding scopes.
Prettier vs. Strict Column Alignment
Prettier focuses on opinionated structure and indent consistency rather than vertical column alignment. In fact, Prettier explicitly strips out aligned spaces around equal signs during saves, so developers who want strict column alignment must configure custom Prettier rules or disable format-on-save for specific files.
This behavior catches many developers off guard. Prettier's maintainers intentionally avoid column alignment because it produces larger git diffs (changing one variable name re-formats ten neighboring lines). If your team demands vertical alignment, you might need to use alternative formatters like ESLint rules with `key-spacing` or configure Prettier ignore blocks using `// prettier-ignore` above specific snippets.
| Tool / Method | Primary Use Case | Setup Required | Best Feature |
|---|---|---|---|
| Format Document (`Shift+Alt+F`) | Overall file indentation and language syntax cleanup | None (Built-in) | Instant standard formatting across all major languages |
| Multi-Cursor (`Ctrl+Alt+Up/Down`) | Custom inline alignment for unique code patterns | None (Built-in) | Total manual control over positioning |
| Better Align Extension | Automated vertical column alignment for `=`, `:`, and `=>` | Install from Marketplace | One-shortcut column alignment across selected blocks |
| Prettier Extension | Opinionated, consistent code style across teams | Install & configure settings | Automated save-time code normalization |
🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.
Troubleshooting Common VS Code Formatting and Alignment Issues
Alignment glitches usually stem from conflicting formatter extensions, mixed tabs and spaces, or automatic save actions overriding manual adjustments. Fixing these issues involves verifying active default formatters in VS Code settings, setting uniform tab sizes, and turning off conflicting save triggers.
When code snaps back to an unaligned state or indents unexpectedly, checking a few core settings fixes the problem quickly.
Fixing Formatter Conflicts and Save Overrides
If your vertical alignment disappears whenever you save, an aggressive code formatter like Prettier is likely resetting your spaces. You can resolve this by changing your default formatter in settings, configuring `.prettierrc` to ignore specific blocks, or disabling `editor.formatOnSave` for specific programming languages.
Check these settings in your `
FAQ
What is the VS Code shortcut to align code?
Use Shift+Alt+F (Windows/Linux) or Shift+Option+F (macOS). This formats the selected code, often aligning variables, assignments, and other elements for readability.
Why isn't the align code shortcut working?
Ensure you have selected the code you want to align. Check your VS Code settings; the shortcut might be remapped or disabled. Also, confirm you're using a language that supports formatting.
Can I customize the align code shortcut?
Yes! Go to File > Preferences > Keyboard Shortcuts. Search for "Format Document" and change the keybinding to your preferred combination.
🛍 See today's best prices on Amazon and grab the option that fits you.