# Formatting

Keep SQL and PL/SQL code consistent and readable with the built-in formatter.

Source: https://www.nexosqlstudio.com/docs/formatting
Language: en
Type: docs

# Formatting

## Database support

Database support does not imply identical features. Connections and SQL worksheets are the starting point; editing, DDL, modeling, transfers, administration and AI operations depend on the engine and workflow. Check the installed version and the relevant guide before relying on an advanced operation.

[Supported databases and feature availability](https://www.nexosqlstudio.com/databases) · [Connection guides](https://www.nexosqlstudio.com/docs/getting-started)

Nexo SQL Studio includes a SQL/PLSQL formatter that normalises whitespace, indentation, keyword casing, commas, operators, joins, and parameter lists. Apply it on demand or wire it into your VS Code **Format on Save** workflow.

## Formatting a File

- **Keyboard shortcut**: `Shift+Alt+F` (VS Code default)
- **Command palette**: `Format Document`
- **Right-click**: Format Document in the editor context menu

## Format on Save

Add this to your VS Code workspace settings to format automatically:

```json
// .vscode/settings.json
{
  "editor.formatOnSave": true,
  "[plsql]": {
    "editor.defaultFormatter": "nexosqlstudio.nexo-sql-studio"
  },
  "[sql]": {
    "editor.defaultFormatter": "nexosqlstudio.nexo-sql-studio"
  }
}
```

## Formatter Options

Configure formatting behaviour in your VS Code settings:

| Setting | Default | Description |
|---------|---------|-------------|
| `nexo-sql-studio.formatter.enable` | `true` | Enable the formatter |
| `nexo-sql-studio.formatter.keywordCase` | `upper` | `upper`, `lower`, or `preserve` |
| `nexo-sql-studio.formatter.indentSize` | `2` | Number of spaces per indent level |
| `nexo-sql-studio.formatter.commaStyle` | `trailing` | Comma placement in multi-line lists |
| `nexo-sql-studio.formatter.maxBlankLines` | `1` | Maximum consecutive blank lines |

## What Gets Formatted

- SQL DML (`SELECT`, `INSERT`, `UPDATE`, `DELETE`, `MERGE`)
- DDL (`CREATE TABLE`, `CREATE INDEX`, …)
- PL/SQL blocks (`BEGIN … END`, `IF`, `LOOP`, `CASE`, …)
- Package specs and bodies
- Stored procedures and functions
- Trigger bodies

## Preserving Regions

Wrap any region with `--@formatter:off` / `--@formatter:on` comments to skip formatting within that block:

```plsql
--@formatter:off
-- hand-crafted alignment
SELECT a, b,
       c  FROM t;
--@formatter:on
```


