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

在Neovim中使用Treesitter时多数代码高亮显示为斜体的问题咨询

Neovim Treesitter代码高亮大量显示为斜体问题

我在Neovim中使用Treesitter实现代码高亮,但大部分代码都显示为斜体。我怀疑这是自身配置问题而非Treesitter的Bug——目前正在搭建一套极简的Neovim配置。想问问这个问题会不会和我在WSL(Windows子系统Linux)上运行Neovim有关?

显示效果示例:
斜体显示的Treesitter代码

我的Treesitter配置文件(treesitter.lua):

require'nvim-treesitter.configs'.setup {
    -- A list of parser names, or "all"
    ensure_installed = { "lua", "c", "javascript", "vimdoc", "rust" },

    -- Install parsers synchronously (only applied to `ensure_installed`)
    sync_install = false,

    -- Automatically install missing parsers when entering a buffer
    -- Recommendation: set to false if you don't have the `tree-sitter` CLI installed locally
    auto_install = true,

    highlight = {
        -- `false` will disable the whole extension
        enable = true,

        -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
        -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
        -- Using this option may slow down your editor, and you may see some duplicate highlights.
        -- Instead of true, it can also be a list of languages
        additional_vim_regex_highlighting = false,
    },
}

我的Neovim版本信息:

  • NVIM v0.10.0-dev-1451+g20dd9f3a2
  • Build type: Release
  • LuaJIT 2.1.1697887905

问题原因及解决方法

  1. 和WSL无关:这个斜体高亮问题基本和WSL环境没有关联,核心原因是配色方案(colorscheme)的配置问题——很多第三方配色会默认将Treesitter的部分高亮组设置为斜体,或是配色未正确覆盖Treesitter的高亮规则。

  2. 快速排查与修复:

    • 临时切换到内置配色(执行:colorscheme default),如果斜体消失,直接锁定当前使用的第三方配色为问题源头。
    • 选中斜体文本后执行:Inspect命令,查看对应的高亮组名称(比如@comment、@variable),然后在配置中手动覆盖该组的样式:
      -- 示例:取消指定高亮组的斜体属性
      vim.api.nvim_create_autocmd("ColorScheme", {
        pattern = "*",
        callback = function()
          vim.cmd([[
            highlight @comment gui=NONE
            highlight @variable gui=NONE
            -- 根据`:Inspect`查到的组名添加对应命令
          ]])
        end,
      })
      
  3. 其他可能情况:

    • 终端模拟器斜体渲染异常:在终端执行tput sitm && echo "Italic test" && tput ritm,如果斜体显示不正常,需要调整终端的字体或渲染设置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 06:55:25