You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在vim-dadbod-ui中激活SQL Tree-sitter语法高亮?

解决vim-dadbod-ui查询窗口启用SQL Tree-sitter高亮的问题

步骤1:确认SQL Tree-sitter Parser已安装

确保你已经安装了SQL的Tree-sitter解析器,在Vim/Neovim中执行:

:TSInstall sql

步骤2:关联dadbod-ui缓冲区到SQL文件类型

vim-dadbod-ui的查询窗口默认文件类型可能不是sql,导致Tree-sitter不生效。在你的vimrc或init.vim中添加以下配置,强制将dadbod-ui的缓冲区设置为SQL类型:

-- 针对不同的dadbod-ui缓冲区类型适配
autocmd FileType dbui setlocal filetype=sql
autocmd FileType dadbod-ui setlocal filetype=sql

-- 或者更精准的缓冲区匹配
autocmd BufEnter * if &filetype ==# 'dadbod-ui' | setlocal filetype=sql | endif

步骤3:确保Tree-sitter高亮功能启用

检查Tree-sitter的高亮配置是否开启,如果你用的是nvim-treesitter,确保配置中有:

require'nvim-treesitter.configs'.setup {
  highlight = {
    enable = true,
    -- 可选:关闭Vim原生正则高亮,完全使用Tree-sitter的高亮逻辑
    additional_vim_regex_highlighting = false,
  },
}

如果是Vim的Tree-sitter插件,确保全局启用高亮:

:TSEnable highlight

步骤4:验证效果

打开dadbod-ui的查询窗口,输入SQL语句后,应该能看到和普通.sql文件一致的Tree-sitter语法高亮。如果仍有问题,可以执行:InspectTree查看当前缓冲区的Tree-sitter解析状态,确认是否正确识别为SQL语法。

内容的提问来源于stack exchange,提问作者Jlchong3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 13:59:51