gitsigns.nvim

lewis6991MIT活跃维护

Neovim 的 Git 集成插件,在缓冲区侧边实时显示增删改标记,支持暂存、撤销和预览代码块差异。

Git integration for buffers

v2.1.0发布于 2026-03-26 17:45 UTC7,179star +6 / 7 天306fork同步于 2026-11-10 23:34 UTC

怎么上手

由 README 提炼,执行前请确认
用你惯用的插件管理器安装即可,无需 setup;如需自定义配置:require('gitsigns').setup {}
硬件要求按 README 说明

README 未说明;仅要求 Neovim >= 0.11.0 和较新版本的 git,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Neovim 插件,把 Git 改动状态直接嵌进缓冲区,让你在编辑器里看差异、暂存和追溯

Neovim 的 Git 集成插件,在缓冲区侧边实时显示增删改标记,支持暂存、撤销和预览代码块差异。

核心能力

  • 在 sign 列标记新增、修改、删除行,并区分已暂存改动
  • 用 :Gitsigns stage_hunk 暂存或重置单个 hunk,支持可视模式选部分行
  • 用 :Gitsigns blame_line 在行尾虚拟文本显示逐行 blame 信息
  • 用 :Gitsigns diffthis 对比当前缓冲区与索引或任意 revision
  • 把改动写入 quickfix/location list,可覆盖整个仓库或已附加缓冲区

容易踩的坑

Neovim 版本必须 >= 0.11.0,旧版本只能用历史 release;使用 Neovim master 开发版时若构建落后可能出问题;git 版本过旧会导致部分功能不可用

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.1.0
  1. v2.1.0最新正式版2026-03-26 · 2026-03-26 17:45 UTC

    2.1.0 (2026-03-26)

    Features

    • setqflist: include untracked files when attach_to_untracked is enabled (1ce96a4), closes #829

    Bug Fixes

    • attach: allow manual attach for untracked files (8c7a4e2)
    • blame: guard WinClosed namespace cleanup (#1469) (7c4faa3)
    • blame: keep cursor line on reblame (6d72ba8), closes #1237
    • blame: reuse buffer when opening diff tab (13588ac), closes #1490
    • calculate line length correct with inlay hints (abf82a6)
    • diff: respect -diff attributes in attach and setqflist (c21acb9), closes #1402
    • diffthis: preserve fold state when staging hunks (e4d4ec8)
    • git: force C locale for git parsing (f7cc685)
    • git: parse renamed files with spaces (253962a)
    • git: refresh cached repo head metadata (d95879a)
    • git: serialize repo operations per repo (060b26c)
    • luarocks: bump scm rockspec revision (d4fdf44), closes #1468
    • qflist: keep renamed paths with base diffs (d9a3de6)
    • qflist: sanitize NUL bytes before VimL conversion (97c6856)
    • repo: update head_oid when checked-out branch moves (f222c40)
    • statuscolumn: scope sign cache per buffer (eaf73f8), closes #1491
    • status: suppress redundant GitSignsUpdate events (b8034e2), closes #1467
    • typing (5dbe0f4)
    • watcher: preserve slash branch names (0a80125)
    • windows: normalize repo path comparisons (5310a7f)
    • word_diff: "No newline at eof" should show once for single hunk ([3121727](https://github.com/lewis69
  2. v2.0.02026-01-09 · 2026-01-09 15:33 UTC
    查看更新说明

    2.0.0 (2026-01-09)

    ⚠ BREAKING CHANGES

    • config: remove support for custom highlight names
    • setup: make optional
    • target Nvim 0.11, drop testing for 0.9.5

    Features

    • actions.blame: add BlameOpts parameter (30ec2bb)
    • actions: add show_commit (6e3ee68)
    • add basic gh integration (aa49c96), closes #839
    • add diffthis options (93f882f), closes #1314
    • blame: do not show hunk if it was added in commit (0ddad02)
    • blame: general improvements (7bf01f0)
    • cache: add support for fetching line ranges (#1414) (5813e48)
    • config: remove support for custom highlight names (74fce28)
    • diffthis: add some rename detection (8dec8da)
    • enable new sign calc (40e235f)
    • enhance status formatting with color codes (e9cfaa0)
    • improve context for logging (4b2c9ab)
    • minor improvements to logging (d62e3ee)
    • move watchers to repo objects (2bf0f73)
    • overhaul repo watcher (a772850)
    • remove border from preview_config default (9a75d9f), closes #1241
    • set buffer name for blame window (588264b)
    • setqflist: improve text in list (b014331)
    • setup: make optional (6933bee), closes #1222
    • show: add navigation mappings (1ee5c1f)
    • show: adjust output to include tree and parent (9dfa82c)
    • support for statuscolumn (b2094c6)
    • win_width: accept winid param (ace6c6c)

    Bug Fixes

  3. v1.0.22025-03-16 · 2025-03-16 16:01 UTC
    查看更新说明

    1.0.2 (2025-03-16)

    Bug Fixes

    • stage_hunk on staged hunk should behave like undo_stage_hunk (5fefc7b)
    • change_base with empty base (751bfae)
  4. v1.0.12025-02-18 · 2025-02-18 10:42 UTC
    查看更新说明

    1.0.1 (2025-02-15)

    Bug Fixes

    • blame: fix popup menu shortcut mappings (420b199), closes #1215
    • current_line_blame: last line show not committed (8b00147), closes #1213
    • stylua (2bc3b47)
  5. v1.0.02025-02-07 · 2025-02-07 11:42 UTC
    查看更新说明

    1.0.0 (2025-02-07)

    ⚠ BREAKING CHANGES

    • deprecate some functions
    • blame: replace dot with dash in blame file type name
    • remove current_line_blame_formatter_opts
    • remove support for yadm
    • config: deprecate highlight groups in config.signs

    Features

    • add highlights for the current line (b29cb58)
    • add staging and update locks (e6e3c3a)
    • add submodule support for gitsigns urls (f074844), closes #1095
    • add type annotations for modules (ac5aba6)
    • async: add async.pcall (562dc47)
    • blame_line: add option to show when not focused (2667904)
    • blame: add Gitsigns blame (25b6ee4)
    • blame: add reblame at commit parent (f4928ba)
    • blame: run formatter with pcall (9ca00df)
    • blame: set filetype to gitsigns.blame (0dc8866), closes #1049
    • config: deprecate highlight groups in config.signs (3d7e49c)
    • config: improve deprecation message (fa42613)
    • deprecate some functions (8b74e56)
    • detect repo errors (899e993)
    • nav: add target option (9291836)
    • nicer errors for failed stages (9521fe8)
    • remove current_line_blame_formatter_opts (92a8fbb)
    • remove support for yadm (61f5b64)
    • set bufname for commit buffers (e4efe9b)
    • share Repo objects across buffers (2593efa)
    • signs: able staged signs by default (b8cf5e8)
    • signs: improve sign generation from hunks (2d2156a)
    • tweak how commit buffers are processed (47c8e3e)
    • use luajit buffers to serialize thread data (233bcbf)

    Bug Fixes

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    gitsigns.nvim

    CI Version LuaRocks License: MIT Dotfyle

    Deep buffer integration for Git

    👀 Preview

    Hunk ActionsLine Blame

    ✨ Features

    • Adds signs to the sign column to indicate added, changed, and deleted lines.

      image

    • Supports different signs for staged changes.

      image

    • Add counts to signs.

      image

    • Stage/unstage hunks with :Gitsigns stage_hunk.

    • Reset hunks with :Gitsigns reset_hunk.

    • Also works on partial hunks in visual mode.

    • Preview hunks inline with :Gitsigns preview_hunk_inline

      image

    • Preview hunks in popup with :Gitsigns preview_hunk

      image

    • Navigate between hunks with :Gitsigns nav_hunk next/prev.

    • Show blame of current buffer using :Gitsigns blame.

      image

    • Show blame information for the current line in popup with :Gitsigns blame_line.

      image

    • Show blame information for the current line in virtual text.

      image

      • Enable with setup({ current_line_blame = true }).
      • Toggle with :Gitsigns toggle_current_line_blame
    • Change the revision for the signs with :Gitsigns change_base <REVISION>.

    • Show the diff of the current buffer with the index or any revision with :Gitsigns diffthis <REVISION>.

    • Show intra-line word-diff in the buffer.

      image

      • Enable with setup({ word_diff = true }).
      • Toggle with :Gitsigns toggle_word_diff.
    • Set the quickfix/location list with changes with :Gitsign setqflist/setloclist.

      image

      Can show hunks for:

      • whole repository (target=all)
      • attached buffers (target=attached)
      • a specific buffer (target=[integer]).
    • Select hunks as a text object.
    • Can use vim.keymap.set({'o', 'x'}, 'ih', '<Cmd>Gitsigns select_hunk<CR>')

    Use b:gitsigns_status or b:gitsigns_status_dict. b:gitsigns_status is formatted using config.status_formatter. b:gitsigns_status_dict is a dictionary with the keys added, removed, changed and head.

    Example:

    set statusline+=%{get(b:,'gitsigns_status','')}
    

    For the current branch use the variable b:gitsigns_head.

    • Use :Gitsigns show <REVISION>:% to :edit the current buffer at <REVISION>

    📋 Requirements

    • Neovim >= 0.11.0

    [!TIP] If your version of Neovim is too old, then you can use a past release.

    [!WARNING] If you are running a development version of Neovim (aka master), then breakage may occur if your build is behind latest.

    • Newish version of git. Older versions may not work with some features.

    🛠️ Installation & Usage

    Install using your package manager of choice. No setup required.

    Optional configuration can be passed to the setup function. Here is an example with most of the default settings:

    require('gitsigns').setup {
      signs = {
        add          = { text = '┃' },
        change       = { text = '┃' },
        delete       = { text = '_' },
        topdelete    = { text = '‾' },
        changedelete = { text = '~' },
        untracked    = { text = '┆' },
      },
      signs_staged = {
        add          = { text = '┃' },
        change       = { text = '┃' },
        delete       = { text = '_' },
        topdelete    = { text = '‾' },
        changedelete = { text = '~' },
        untracked    = { text = '┆' },
      },
      signs_staged_enable = true,
      signcolumn = true,  -- Toggle with `:Gitsigns toggle_signs`
      numhl      = false, -- Toggle with `:Gitsigns toggle_numhl`
      linehl     = false, -- Toggle with `:Gitsigns toggle_linehl`
      word_diff  = false, -- Toggle with `:Gitsigns toggle_word_diff`
      watch_gitdir = {
        follow_files = true
      },
      auto_attach = true,
      attach_to_untracked = false,
      current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
      current_line_blame_opts = {
        virt_text = true,
        virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
        delay = 1000,
        ignore_whitespace = false,
        virt_text_priority = 100,
        use_focus = true,
      },
      current_line_blame_formatter = '<author>, <author_time:%R> - <summary>',
      blame_formatter = nil, -- Use default
      sign_priority = 6,
      update_debounce = 100,
      status_formatter = nil, -- Use default
      max_file_length = 40000, -- Disable if file is longer than this (in lines)
      preview_config = {
        -- Options passed to nvim_open_win
        style = 'minimal',
        relative = 'cursor',
        row = 0,
        col = 1
      },
    }
    

    For information on configuring Neovim via lua please see nvim-lua-guide.

    🎹 Keymaps

    Gitsigns provides an on_attach callback which can be used to setup buffer mappings.

    Here is a suggested example:

    require('gitsigns').setup{
      ...
      on_attach = function(bufnr)
        local gitsigns = require('gitsigns')
    
        local function map(mode, l, r, opts)
          opts = opts or {}
          opts.buffer = bufnr
          vim.keymap.set(mode, l, r, opts)
        end
    
        -- Navigation
        map('n', ']c', function()
          if vim.wo.diff then
            vim.cmd.normal({']c', bang = true})
          else
            gitsigns.nav_hunk('next')
          end
        end)
    
        map('n', '[c', function()
          if vim.wo.diff then
            vim.cmd.normal({'[c', bang = true})
          else
            gitsigns.nav_hunk('prev')
          end
        end)
    
        -- Actions
        map('n', '<leader>hs', gitsigns.stage_hunk)
        map('n', '<leader>hr', gitsigns.reset_hunk)
    
        map('v', '<leader>hs', function()
          gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
        end)
    
        map('v', '<leader>hr', function()
          gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
        end)
    
        map('n', '<leader>hS', gitsigns.stage_buffer)
        map('n', '<leader>hR', gitsigns.reset_buffer)
        map('n', '<leader>hp', gitsigns.preview_hunk)
        map('n', '<leader>hi', gitsigns.preview_hunk_inline)
    
        map('n', '<leader>hb', function()
          gitsigns.blame_line({ full = true })
        end)
    
        map('n', '<leader>hd', gitsigns.diffthis)
    
        map('n', '<leader>hD', function()
          gitsigns.diffthis('~')
        end)
    
        map('n', '<leader>hQ', function() gitsigns.setqflist('all') end)
        map('n', '<leader>hq', gitsigns.setqflist)
    
        -- Toggles
        map('n', '<leader>tb', gitsigns.toggle_current_line_blame)
        map('n', '<leader>tw', gitsigns.toggle_word_diff)
    
        -- Text object
        map({'o', 'x'}, 'ih', gitsigns.select_hunk)
      end
    }
    

    🔗 Plugin Integrations

    vim-fugitive

    When viewing revisions of a file (via :0Gclog for example), Gitsigns will attach to the fugitive buffer with the base set to the commit immediately before the commit of that revision. This means the signs placed in the buffer reflect the changes introduced by that revision of the file.

    trouble.nvim

    If installed and enabled (via config.trouble; defaults to true if installed), :Gitsigns setqflist or :Gitsigns setloclist will open Trouble instead of Neovim's built-in quickfix or location list windows.

    🚫 Non-Goals

    Implement every feature in vim-fugitive

    This plugin is actively developed and by one of the most well regarded vim plugin developers. Gitsigns will only implement features of this plugin if: it is simple, or, the technologies leveraged by Gitsigns (LuaJIT, Libuv, Neovim's API, etc) can provide a better experience.

    Support for other VCS

    There aren't any active developers of this plugin who use other kinds of VCS, so adding support for them isn't feasible. However a well written PR with a commitment of future support could change this.

    🔌 Similar plugins