Editing & Formatting SQL¶
This section covers the experimental formatting capabilities and the tree-sitter based editing features available in the plugin.
Formatting¶
The plugin provides basic SQL formatting functionality. Please note that this feature is currently experimental and not all SQL constructs are fully implemented yet.
Formatting Rules¶
The formatter adheres to the following conventions to ensure consistency:
- UPPERCASE: Database names, table names, field names, and field aliases.
- lowercase: All other SQL keywords and syntax.
Editing¶
Editing features are powered by Tree-sitter nodes, allowing for precise structural manipulation of your SQL code. You can define custom movement and editing keymaps in your setup configuration.
Configuration¶
Below is an example configuration that sets up keymaps for commenting, deleting, and navigating between specific nodes:
keymaps = {
-- Comment nodes
["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" } },
-- Delete nodes
["gdq"] = { "delete_node", { "statement" } },
["gds"] = { "delete_node", { "select_expression" } },
["gdw"] = { "delete_node", { "where" } },
["gdf"] = { "delete_node", { "term" } },
["gdb"] = { "delete_node", { "binary_expression" } },
-- Navigation
["]s"] = { "jump_to_next", { "statement" } },
["[s"] = { "jump_to_prev", { "statement" } },
},
Understanding Node Arguments¶
The functions comment_node, delete_node, jump_to_next, and jump_to_prev accept a single argument: the node type (e.g., "statement", "where", "term").
!!! tip "Finding Node Types" To discover the specific node type under your cursor, you can use the built-in Neovim command: :InspectTree