Skip to content

Configuration

All options are passed to require('vim-teradata').setup({ ... }). All fields are optional except users.

require('vim-teradata').setup({
  users = {
    { log_mech = 'TD2', user = 'USER', tdpid = 'HOST' },
  },
  -- optional settings shown with their defaults:
  retlimit = 100,
  replacements = {},
  ft = { 'sql', 'teradata' },
  picker = 'auto',
  sql_detection = 'always',
  timeout_ms = nil,
  history_max = nil,
  sep = '~',
  edit_enabled = true,
  preview_updates = true,
  null_token = 'NULL',
  edit_keymaps = { toggle = 'E', save = 'S', cancel = 'C' },
  rerun_keymaps = { sql = 'g.', result = '.' },
  filter_db = nil,
  export = {
    enabled = true,
    keymap = 'F',
    confirm = true,
    operator = 'auto',
    max_sessions = 4,
    head_lines = nil,
    timeout_ms = nil,
    tpt_script = nil,
  },
  exports_dir_name = 'exports',
  virtual = {
    footer_default = 'off',
    footer_scope = 'displayed',
    yank_quick_calc = false,
    persist_columns = true,
    header_prefix = 'ƒ ',
    engine = 'auto',
    edit_target = 'table',
    keymaps = {
      footer_next = 'gS',
      footer_prev = 'gs',
      footer_db = 'gD',
      quick_calc = '<leader>=',
      add_column = '=',
    },
  },
  -- history_dir = vim.fn.stdpath('data') .. '/teradata/history',
  -- bookmarks_dir = vim.fn.stdpath('data') .. '/teradata/bookmarks',
  -- data_dir = vim.fn.stdpath('data') .. '/teradata',
})

users (table[])

Default: {}

List of connection profiles. The first profile is the default active user.

users = {
  {
    log_mech = 'TD2',   -- logon mechanism (e.g. 'TD2', 'LDAP', 'KRB5')
    user     = 'USER',  -- username backed by tdwallet
    tdpid    = 'HOST',  -- Teradata host or IP address
  },
}

Security Note: Passwords are NEVER stored by vim-teradata or written to disk. They are retrieved at logon time from tdwallet using $tdwallet(<user>).


replacements (table)

Default: {}

String substitutions applied to every query before it is sent to BTEQ. Useful for portable scripts and environment-specific database names:

replacements = {
  ['${DB_NAME}'] = 'PROD_DB',
  ['${WORK_DB}'] = 'WORK_DB_001',
}

retlimit (number)

Default: 100

Maximum number of rows returned per :TDO / :TDV query. Controls memory and latency.

retlimit = 100

ft (string[])

Default: { "sql", "teradata" }

File extensions and filetypes that activate vim-teradata. The plugin registers each extension via vim.filetype.add. See Filetypes.

ft = { 'sql', 'teradata', 'btq' }

picker (string)

Default: "auto"

Picker backend used by :TDR and selection dialogs:

picker = 'auto'

sql_detection (string)

Default: "always"

Controls whether .sql files are treated as teradata:

  • "always": all .sql buffers get filetype teradata.
  • "never": do not map .sql to teradata.
  • "modeline": inspect first/last 5 lines for teradata or bteq.
sql_detection = 'always'

timeout_ms (number | nil)

Default: nil (disabled)

BTEQ job execution timeout in milliseconds. Set to nil or 0 to disable the timeout.

In a persistent session (:TDSession), the timeout applies to each command individually, counted from the moment it is sent to BTEQ (time spent waiting in the queue does not count). A command that times out closes the session.

timeout_ms = 30000 -- 30 seconds

history_max (number | nil)

Default: nil (unlimited)

Maximum number of query history runs kept on disk before pruning older entries. Set to nil to disable pruning.

history_max = 500

keymaps (table)

Default: see below

Normal-mode mappings registered in every Teradata buffer to invoke node-aware editing functions ("OPE operations"). Each entry maps a key sequence to either:

  • A string: name of an OPE function applied at the cursor node.
  • A table { "func_name", { "node_type", ... } }: function plus the tree-sitter node type to act on around the cursor.

Default keymaps:

keymaps = {
  ["gcu"] = "uncomment_node",
  ["gcq"] = { "comment_node", { "statement" } },
  ["gcs"] = { "comment_node", { "select_expression" } },
  ["gcw"] = { "comment_node", { "where" } },
  ["gcf"] = { "comment_node", { "term" } },
  ["gcb"] = { "comment_node", { "binary_expression" } },
  ["gdq"] = { "delete_node",  { "statement" } },
  ["gds"] = { "delete_node",  { "select_expression" } },
  ["gdw"] = { "delete_node",  { "where" } },
  ["gdf"] = { "delete_node",  { "term" } },
  ["gdb"] = { "delete_node",  { "binary_expression" } },
  ["grs"] = { "copy_node",    { "select_expression" } },
  ["]s"]  = { "jump_to_next", { "statement" } },
  ["[s"]  = { "jump_to_prev", { "statement" } },
}

See Editing & Formatting for the full list of available OPE functions and node types.


sep (string)

Default: "~"

Field separator used in BTEQ result CSV files and TPT exports. Change only if your data regularly contains ~. Full exports (:TDExport) also refuse a sep containing a single quote or newline.

sep = '~'

edit_enabled (boolean)

Default: true

Enables in-grid editing of query results. See Editing results.

edit_enabled = true

preview_updates (boolean)

Default: true

When true, saving edits in a result buffer opens the generated UPDATE statements in a scratch buffer for review; nothing is sent to BTEQ until you press <CR> in that buffer.

preview_updates = true

null_token (string)

Default: "NULL"

Text BTEQ uses to render NULL in result exports (.set null). The same token typed into a cell in edit mode means SQL NULL.

null_token = 'NULL'

edit_keymaps (table)

Default: { toggle = "E", save = "S", cancel = "C" }

Result-buffer local mappings for in-grid editing mode:

edit_keymaps = {
  toggle = 'E',  -- toggle edit mode
  save   = 'S',  -- stage / preview updates
  cancel = 'C',  -- discard pending edits
}

rerun_keymaps (table)

Default: { sql = "g.", result = "." }

Mappings that re-run the latest query (see :TDRerun):

rerun_keymaps = {
  sql    = 'g.',  -- installed in every Teradata buffer
  result = '.',   -- installed in every result buffer
}

The two defaults differ on purpose: in a Teradata buffer . must keep its normal meaning (repeat the last change), so the mnemonic g. is used instead. A result buffer is nofile and non-modifiable, so . is free there.

Set either entry to nil or "" to skip that mapping:

rerun_keymaps = { sql = '<leader>rr', result = '.' }

filter_db (string | nil)

Default: nil

Optional Lua pattern that limits which database names are imported by :TDSync. Useful on systems with thousands of irrelevant catalogs.

filter_db = '^PROD_'  -- only import databases starting with PROD_

export (table)

Configuration for full query result exports via TPT (:TDExport and the F key).

export = {
  enabled      = true,    -- enable/disable full export feature
  keymap       = "F",     -- result buffer keymap (or "gF", false to disable)
  confirm      = true,    -- show confirmation dialog before running
  operator     = "auto",  -- TPT operator: "auto", "export", or "selector"
  max_sessions = 4,       -- sessions for EXPORT operator
  head_lines   = nil,     -- rows loaded for preview (<CR> in :TDJ); nil = retlimit
  timeout_ms   = nil,     -- TPT process timeout in milliseconds (nil = disabled)
  tpt_script   = nil,     -- custom TPT script path replacing bundled templates
}

export.enabled (boolean)

Default: true

When set to false, the F keymap is not bound in result buffers and :TDExport is refused.

export.keymap (string | false)

Default: "F"

Result-buffer mapping that triggers a full export. Set to false or "" to disable the key while keeping :TDExport available. Set to "gF" if you wish to retain Vim's F{char} backward motion in result buffers.

export.confirm (boolean)

Default: true

When true, displays a confirmation dialog showing query metadata, row count, size estimate, target file, and operator before initiating the TPT job. Set to false to start exports immediately.

export.operator (string)

Default: "auto"

The TPT operator used for the export:

  • "auto": Uses the multi-session EXPORT operator with query wrapping when supported; falls back automatically to SELECTOR (report mode) if the query cannot be wrapped or fails on complex data types.
  • "export": Strictly uses the multi-session EXPORT operator (FastExport protocol). Queries that cannot be wrapped are refused.
  • "selector": Strictly uses the SELECTOR operator in report mode (single session, query unchanged). Recommended for environments without utility session permissions.

export.max_sessions (number)

Default: 4

Number of concurrent sessions allocated to the EXPORT operator. Must be a positive integer. Ignored when the query runs under the SELECTOR operator.

export.head_lines (number | nil)

Default: nil

Number of rows loaded into a preview grid when pressing <CR> on a finished export job in :TDJ. When nil, defaults to the value of retlimit.

export.timeout_ms (number | nil)

Default: nil

Timeout for the TPT execution process in milliseconds. Set to nil or 0 to disable the timeout. This setting is independent of the general query timeout_ms.

export.tpt_script (string | nil)

Default: nil

Path to a custom TPT script template replacing the bundled templates (export_query or export_query_selector).


exports_dir_name (string)

Default: "exports"

Subdirectory name under history_dir where full export CSV files are saved (<history_dir>/exports/<id>.csv).


virtual (table)

Configuration for in-grid virtual answerset features (summary footers, selection quick-calc, computed columns, server pushdown, and volatile-table materialization). See Virtual answersets.

virtual = {
  footer_default  = 'off',        -- initial summary footer mode
  footer_scope    = 'displayed',  -- 'displayed' | 'all'
  yank_quick_calc = false,        -- copy tab-separated stats on quick-calc
  persist_columns = true,         -- persist virtual columns per query hash
  header_prefix   = 'ƒ ',         -- prefix for virtual column headers
  engine          = 'auto',       -- 'auto' | 'lua' | 'db'
  edit_target     = 'table',      -- 'table' | 'volatile'
  keymaps = {
    footer_next = 'gS',           -- cycle footer forward
    footer_prev = 'gs',           -- cycle footer backward
    footer_db   = 'gD',           -- exact Teradata totals (SQL pushdown)
    quick_calc  = '<leader>=',    -- visual mode quick-calc popup
    add_column  = '=',            -- prompt to add computed virtual column
  },
}

virtual.footer_default (string)

Default: "off"

Initial summary footer mode when opening a result grid: "off", "sum", "avg", "min", "max", "count", "nulls", or "distinct".

virtual.footer_scope (string)

Default: "displayed"

Controls which rows are aggregated in the summary footer:

  • "displayed": Aggregates over currently visible rows that match active in-grid <CR> filters.
  • "all": Aggregates across all loaded rows in the result set, ignoring <CR> filters.

virtual.yank_quick_calc (boolean)

Default: false

When set to true, triggering quick-calc (<leader>= or :TDCalc) automatically copies a tab-separated line (sum\tavg\tmin\tmax) into the unnamed register "".

virtual.persist_columns (boolean)

Default: true

When true, computed virtual columns added via :TDCol are stored in <data_dir>/virtual_columns.json keyed by a normalized SHA-256 hash of the query. Re-running the query (:TDRerun, .) or opening it from history restores its computed columns automatically.

virtual.header_prefix (string)

Default: "ƒ "

Prefix prepended to virtual column headers in the result grid.

virtual.engine (string)

Default: "auto"

Controls how footer totals are calculated:

  • "auto": Client-side Lua by default; displays (partial) when results are truncated by retlimit and (≈) when numbers exceed 15 significant digits.
  • "lua": In-memory Lua only (gD pushdown remains available on demand).
  • "db": Automatically triggers Teradata SQL pushdown (gD) whenever cycling the footer with gS.

virtual.edit_target (string)

Default: "table"

Specifies the destination for in-grid edits (<E> / <S>):

  • "table": Generates and executes UPDATE statements against the real database source table.
  • "volatile": Available when the answerset is materialized (:TDMaterialize). Generates and executes UPDATE statements against the session volatile table copy, allowing safe sandbox editing without touching production tables. Can also be toggled with :TDEditTarget.

virtual.keymaps (table)

Keymaps local to result buffers:

  • footer_next (string, default "gS"): Cycle summary footer forward.
  • footer_prev (string, default "gs"): Cycle summary footer backward.
  • footer_db (string, default "gD"): Compute exact database totals via Teradata pushdown.
  • quick_calc (string, default "<leader>="): Open quick-calc popup in visual mode.
  • add_column (string, default "="): Prompt to add a computed virtual column.

Directory paths

  • history_dir (string): Directory for query history files (queries/, resultsets/, and exports/). Defaults to vim.fn.stdpath('data') .. '/teradata/history'.
  • bookmarks_dir (string): Directory for global and user bookmarks. Defaults to vim.fn.stdpath('data') .. '/teradata/bookmarks'.
  • data_dir (string): Directory for the autocomplete metadata cache (sql-autocomplete). Defaults to vim.fn.stdpath('data') .. '/teradata'.