SQL Formatter

Notepad++ plugin

dbt & Jinja

dbt models aren't plain SQL — they're full of Jinja templating: {{ ref('orders') }}, {{ var('lookback_days') }}, {# explanatory comments #} and {% if/for %} blocks. The formatter recognizes these constructs as their own token category and formats around them, without ever breaking a brace, quote or macro argument.

{{ ref(...) }} and {{ var(...) }} stay intact

A model that references other models via ref() or source(), or a configurable variable via var(), gets formatted like an ordinary SELECT — but the Jinja expression itself is carried over literally, including the exact spacing inside the double braces that dbt itself expects.

Before

select order_id, customer_id, amount from {{ ref('stg_orders') }} where amount > {{ var('min_amount') }}

After

select order_id
     , customer_id
     , amount
  from {{ ref('stg_orders') }}
 where amount > {{ var('min_amount') }}

Comments, control flow, and an escape hatch: @formatter:off

{# ... #} Jinja comments and {% ... %} control-flow tags ({% if %}, {% for %}, {% set %}) are recognized just like {{ ... }} expressions and left unchanged. Want a block exempted from the formatter entirely — a macro call with unusual formatting you've deliberately kept, say — wrap it in -- @formatter:off and -- @formatter:on.

Before

select
{{ ref('orders') }}.order_id
-- @formatter:off
from     weird_legacy_table   x
-- @formatter:on
{% if is_incremental() %}
where order_id > (select max(order_id) from {{ this }})
{% endif %}

After

select {{ ref('orders') }}.order_id
-- @formatter:off
from     weird_legacy_table   x
-- @formatter:on
{% if is_incremental() %}
 where order_id > (select max(order_id) from {{ this }})
{% endif %}

Frequently asked questions

Does this also work with nested macros and multiple ref() calls on one line?

Yes — every {{ ... }} expression is recognized independently, even when several appear on the same SELECT line or when ref()/var() is nested inside a larger expression.

Do I need to configure anything special to recognize dbt files?

No, Jinja recognition is always on and works on any file — there's no separate 'dbt mode' toggle needed.