How to Align Code in Visual Studio Code

Aligning code helps make it more readable and consistent. There are two methods to align code in Visual Studio Code: using keyboard shortcuts and auto-formatting code on saving, which we explain in this article. This guide will show you how to use keyboard shortcuts to align your code quickly.

Align code with Keyboard shortcuts

Code Alignment is available in Visual Studio Code through the following shortcuts or key combinations:

  1. Open the file you want to align. You’ll notice that I have an unaligned code.
    Unaligned Code
    Open the code file you want to align.

    Select the code you want to align and use the following shortcut:
    On Windows: Shift + Alt + F
    On macOS: Shift + Option + F
    On Linux: Ctrl + Shift + I

    Press the mentioned key combinations to align the selected code.

Leave a Comment