Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Sort Import LinesNew to Visual Studio Code? Get it now.
Sort Import Lines

Sort Import Lines

Nima Kalhor

|
9 installs
| (2) | Free
A VSCode command to sort import statements by line length
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

📦 VSCode Extension: Sort & Group TS/JS Imports – Smart Import Organizer

A powerful and opinionated import sorter for TypeScript/JavaScript files. This extension intelligently reformats and reorders your import statements based on clear grouping rules:


✨ Features

✅ Automatically removes duplicate imports ✅ Merges multi-line and broken imports into single lines before processing ✅ Sorts imports alphabetically within groups ✅ Groups imports based on path similarity ✅ Special handling for grouped imports with odd count (single-line item comes first) ✅ Ignores non-import code ✅ Works with both TypeScript (.ts, .tsx) and JavaScript files (.js, .jsx)


⚙️ How It Works

Step 1: Scans the selected code (or entire file) for import statements.

Step 2: Normalizes import lines (removes line breaks between import and ;).

Step 3: Groups import statements based on similarity in module path.

Step 4: Within each group, sorts individual items and reorders single-line and multi-line imports based on best-practice formatting.

Example:

Before

import { b } from 'b';
import {
  d,
  c
} from 'a';
import z from 'z';

After

import z from 'z';
import { b } from 'b';
import {
  c,
  d,
} from 'a';

🚀 How To Use

  1. Select one or more import lines in your editor.

  2. Run the command: Sort & Group TS/JS Imports

    • (Right-click > Command Palette > search: Sort & Group)
  3. Done ✅


📦 Requirements

  • VS Code ≥ v1.80.0
  • Works best with TypeScript or JavaScript projects

🧠 Extension Commands

Command Description
Sort & Group TS/JS Imports Sorts and formats selected imports

💬 Feedback & Issues

Found a bug or want to request a feature? Open an issue


📝 License

MIT © 2025

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft