Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Compact SQL FormatterNew to Visual Studio Code? Get it now.
Compact SQL Formatter

Compact SQL Formatter

vscode-sql-formatter-compact

|
4 installs
| (1) | Free
极度紧凑、强迫症友好的 SQL 格式化工具。A strictly compact, highly customizable SQL formatter with flush-left keyword alignment.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Compact SQL Formatter (VS Code Extension)

Note: For the Chinese version of this document, see README_zh.md.

This is the official VS Code extension for the tightly optimized @guojc1/sql-formatter-compact engine. It is designed specifically for developers who have strict requirements for compact and clean SQL layouts.

🌟 Key Features

  • Relative Flush-Left Alignment: Resolves the annoying double-indentation issue for WHERE, AND, LEFT JOIN relative to FROM.
  • Pre-comma Layout (commaPosition: before): Elegantly places commas at the beginning of the line while keeping inline comments intact at the end of the previous line.
  • CASE Inline: Compresses long case-when statements into a single line to keep the code extremely compact.
  • Magic Comments: Supports /* sql-formatter-compact-disable */ to skip formatting for specific blocks of SQL.

⚙️ Configuration Priority

This extension is highly flexible and reads configurations based on the following priority (from highest to lowest):

  1. Workspace / Project Config: If a .sql-formatter-compact.json or sqlfmt.json file is found in the root directory of your currently opened VS Code workspace, it will be used. This is highly recommended for team consistency.
  2. Global User Config: If no workspace config is found, it will look for the same JSON files in your Operating System's User Home Directory (e.g., C:\Users\YourName or ~). This is great for standalone SQL scripts!
  3. VS Code Settings GUI: If no physical files are found, it falls back to the settings configured directly within the VS Code UI (Ctrl + , -> Search "Compact SQL Formatter").

💻 Example Config File (sqlfmt.json)

{
  "language": "hive",
  "commaPosition": "before",
  "newlineAfterClause": false,
  "expressionWidth": 150,
  "tabWidth": 2
}

🚀 How to Use

  1. Open any .sql file in VS Code.
  2. Ensure the language mode in the bottom right corner is set to SQL.
  3. Press Shift + Alt + F (or right-click and select "Format Document").

License: MIT

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