Sorting lines alphabetically in VS Code is a built-in feature, so you don’t need any extensions to get it done.
Here are the two ways to handle it, depending on whether you prefer the Command Palette or a keyboard shortcut.
Option 1: Using the Command Palette (Easiest)
- Select the text you want to sort. If you want to sort the entire file, press
Ctrl+A(Windows/Linux) orCmd+A(Mac). - Open the Command Palette by pressing
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(Mac). - Type „Sort Lines Ascending“ and press Enter.
Option 2: Case Sensitive vs. Case Insensitive
VS Code gives you a few different flavors of sorting depending on how you want to handle Capital letters:
| Command | Result |
|---|---|
| Sort Lines Ascending | Standard alphabetical order (A-Z). |
| Sort Lines Descending | Reverse alphabetical order (Z-A). |
| Sort Lines (Case Sensitive) | Groups uppercase (A-Z) separately from lowercase (a-z). |
| Sort Lines (Unique) | Sorts the lines and removes duplicates in one go. |
Pro Tip: Multi-Cursor Sorting
If you have multiple blocks of text (like three different lists in one file) and you want to sort them individually:
- Highlight the first block.
- Hold
Alt(orOptionon Mac) and highlight the second and third blocks. - Run the Sort Lines Ascending command. VS Code will sort each block independently rather than merging them all together.