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

nvim-tree中Git状态图标(已暂存/未暂存等)不显示问题求助

Nvim-Tree Git状态图标不显示问题排查方案

我在基于Lua配置的Neovim中安装了nvim-tree/nvim-tree和nvim-tree/nvim-web-devicons插件,但文件/文件夹左侧的Git状态图标(已暂存、未暂存、重命名等)无法显示。

正常显示效果如下:
Git状态图标正常显示效果

现有配置文件

web-devicon.lua

require("nvim-web-devicons").setup({
    -- your personnal icons can go here (to override)
    -- you can specify color or cterm_color instead of specifying both of them
    -- DevIcon will be appended to `name`
    override = {
        fish = {
            icon = "",
            color = "#428850",
            cterm_color = "65",
            name = "fish",
        },
    },
    -- globally enable different highlight colors per icon (default to true)
    -- if set to false all icons will have the default icon's color
    color_icons = true,
    -- globally enble default icons (default to false)
    -- will get overriden by `get_icons` option
    default = true,
    -- globally enable "strict" selection of icons - icon will be looked up in
    -- different tables, first by filename, and if not found by extension; this
    -- prevents cases when file doesn't have any extension but still gets some icon
    -- because its name happened to match some extension (default to false)
    strict = true,
    -- same as `override` but specifically for overrides by filename
    -- takes effect when `strict` is true
    override_by_filename = {
        [".gitignore"] = {
            icon = "",
            color = "#f1502f",
            name = "Gitignore",
        },
    },
    -- same as `override` but specifically for overrides by extension
    -- takes effect when `strict` is true
    override_by_extension = {
        ["log"] = {
            icon = "",
            color = "#81e043",
            name = "Log",
        },
    },
})

nvim-tree.lua

-- following options are the default
-- each of these are documented in `:help nvim-tree.OPTION_NAME`

local status_ok, nvim_tree = pcall(require, "nvim-tree")
if not status_ok then
    return
end

--[[ local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") ]]
--[[ if not config_status_ok then ]]
--[[    return ]]
--[[ end ]]

--[[ local tree_cb = nvim_tree_config.nvim_tree_callback ]]

nvim_tree.setup({
    filters = {
        dotfiles = false,
        git_clean = false,
        no_buffer = false,
        custom = {
            "node_modules", -- filter out node_modules directory
            ".git", -- filter out .git directory
        },
        exclude = {},
    },
    disable_netrw = true,
    hijack_netrw = true,
    --open_on_setup = false,
    open_on_tab = false,
    hijack_cursor = false,
    update_cwd = true,
    hijack_directories = {
        enable = true,
        auto_open = true,
    },
    diagnostics = {
        enable = true,
        icons = {
            hint = "",
            info = "",
            warning = "",
            error = "",
        },
    },
    update_focused_file = {
        enable = true,
        update_cwd = true,
        ignore_list = {},
    },
    git = {
        enable = true,
        ignore = true,
        timeout = 500,
    },
    view = {
        width = 30,
        --height = 30,
        hide_root_folder = false,
        side = "left",
        --auto_resize = true,
        mappings = {
            custom_only = false,
        },
        number = false,
        relativenumber = false,
    },
    actions = {
        --quit_on_open = true,
        --window_picker = { enable = true },
    },
    renderer = {
        highlight_git = true,
        root_folder_modifier = ":t",
        icons = {
            show = {
                file = true,
                folder = true,
                folder_arrow = true,
                git = true,
            },
            glyphs = {
                default = "",
                symlink = "",
                git = {
                    unstaged = "U",
                    staged = "S",
                    unmerged = "UM",
                    renamed = "R",
                    deleted = "D",
                    untracked = "",
                    ignored = "I",
                },
                folder = {
                    default = "",
                    open = "",
                    empty = "",
                    empty_open = "",
                    symlink = "",
                },
            },
        },
    },
})

packer.lua

vim.cmd([[packadd packer.nvim]])

return require("packer").startup(function(use)
    --[[ rest of the plugins ]]

    use({ --- lualine
        "nvim-lualine/lualine.nvim",
        requires = { "nvim-tree/nvim-web-devicons" },
    })

    use({ -- LSPSaga
        "glepnir/lspsaga.nvim",
        opt = true,
        branch = "main",
        event = "LspAttach",
        config = function()
            require("lspsaga").setup({})
        end,
        requires = {
            { "nvim-tree/nvim-web-devicons" },
            --Please make sure you install markdown and markdown_inline parser
            { "nvim-treesitter/nvim-treesitter" },
        },
    })

    --[[ rest of the plugins ]]
end)

排查与解决思路

  1. 验证Git仓库环境

    • 确认当前工作目录是Git仓库,执行git status检查是否有未暂存、未跟踪的文件,nvim-tree仅在Git仓库且文件有状态变化时显示图标。
    • 若测试文件在.gitignore列表中,当前配置git.ignore = true会隐藏其状态,可临时改为false验证。
  2. 修正nvim-tree核心配置

    • 检查git.timeout值,500ms可能导致Git状态获取超时,建议调整为1000ms。
    • 确认renderer.icons.show.git = true无拼写错误,该选项是Git图标显示的开关。
  3. 调整插件依赖与加载顺序

    • 在packer中给nvim-tree添加明确的nvim-web-devicons依赖,确保devicons先于nvim-tree加载:
      use({
          "nvim-tree/nvim-tree.lua",
          requires = { "nvim-tree/nvim-web-devicons" },
          config = function() require("nvim-tree").setup(...) end
      })
      
    • 确保web-devicon.lua的配置文件在nvim-tree.lua之前被加载。
  4. 检查字体兼容性

    • 终端必须使用支持Nerd Font的字体(如JetBrains Mono Nerd Font、Fira Code Nerd Font),非Nerd Font无法显示特殊图标。
    • 可临时将Git图标替换为标准Nerd Font字符(比如unstaged = ""),验证是否能正常显示。
  5. 清理缓存与更新插件

    • 执行:PackerClean清除旧插件,再用:PackerInstall重新安装。
    • 运行:PackerSync更新所有插件,旧版本可能存在兼容性bug。
  6. 排查插件冲突

    • 用nvim --clean启动,仅加载nvim-tree和devicons,验证是否正常显示,排除其他配置干扰。
    • 逐一禁用其他插件,排查是否存在冲突项。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 03:25:08