Skip to main content
Back to Extensions Directory
coc-git icon

Git extension for coc.nvim

Installation CommandVim prompt
:CocInstall coc-git
GitHub owner
Neoclide
Version
v2.7.15
npm package
coc-git
Requirements
coc ^0.0.82
License
MIT
Repository
GitHub
npm latest published 2026-09-30Registry checked 2026-10-01Registry summary

A practical first workflow

Use coc-git to inspect and stage individual changes from Vim or Neovim. Its normal gutter compares the buffer with Git’s index, so a change disappears from that gutter after staging. That does not mean the edit was lost. This example checks the index and the remaining working-tree diff separately.

Create two changes in a disposable repository

Install with :CocInstall coc-git. In a macOS or Linux terminal, create a temporary repository with one committed file. The commit identity and signing option below apply only to this example commit.

bash snippet
1demo_dir=$(mktemp -d)
2cd "$demo_dir"
3git init
4printf 'one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\n' > demo.txt
5git add demo.txt
6git -c user.name="Documentation Example" \
7 -c user.email="example@example.com" \
8 -c commit.gpgsign=false commit -m "Initial example"
9nvim demo.txt

Use vim instead of nvim for Vim. Change line 1 from one to ONE and line 9 from nine to NINE, then save with :w. Keeping the changes apart makes it possible to stage one hunk without staging the other.

Stage one hunk and verify what will be committed

vim snippet
1:1
2:CocCommand git.chunkInfo
3:CocCommand git.chunkStage
4:!git diff --cached -- demo.txt
5:!git diff -- demo.txt

The cached diff should contain only one → ONE. The ordinary diff should contain only nine → NINE. The file still contains both edits. If you see a different result, inspect those two diffs before committing; the gutter alone does not describe everything in the index.

Return to line 1 and run :CocCommand git.chunkUnstage. The cached diff should become empty, the ordinary diff should contain both changes, and the edited text should remain. git.chunkUndo is a different operation that reverts a buffer hunk; use git.chunkUnstage when you want to keep the text and remove it from the next commit.

When signs or hunk commands do not match expectations

  • Check :echo exepath('git'), :pwd and :!git status --short. Start with a tracked file in a repository that has a commit, as above; an untracked file is not the same case.
  • Check git.enableGutters and git.diffRevision. This example uses the default empty revision, which compares against the index. A custom revision changes that comparison. Run :CocCommand git.refresh after investigating an external Git operation.
  • git.enableStagedGutters is off by default. Enable it if you also want staged-change signs; use the two Git diffs to distinguish staged and unstaged work.
  • “Not positioned in git chunk” means the cursor is not in a hunk available to that operation. Go back to the changed line and check the current diff. If Git reports an error, inspect the Git output through :CocCommand workspace.showOutput.

Verified on macOS with Neovim 0.12.4 and the coc-git 2.7.14 npm package: staging changed only the first hunk in the index; unstaging emptied the index diff and preserved both edits. This example does not cover merge conflicts or every Git status.

Site-authored guidance reviewed on 2026-09-22. Content sources and maintainers · Choose extension responsibilities

Published Package Summary

coc-git

coc-git logo

Git integration of coc.nvim.

Note: many useful features not implemented, it's recommended to use plugin like vim-fugitive at the same time.

Install

In your vim/neovim, run command:

:CocInstall coc-git

Why

  • Always async.
  • Always refresh on TextChange.
  • Powerful list support.
  • Semantic commit and github issues completion support.
  • Undo, stage & unstage change chunk under current cursor.

Features

  • Sign support for git status of current buffer.
  • Git status of current project, by g:coc_git_status.
  • Git status of current buffer, byb:coc_git_status.
  • Git status of current line, byb:coc_git_blame for statusline, and addGBlameToVirtualText for inline blames.
  • Git related lists, including issues, gfiles, gstatus, gchanges, gchunks, commits, branches & bcommits
  • Keymaps for git chunks, including <Plug>(coc-git-chunkinfo) <Plug>(coc-git-nextchunk) & <Plug>(coc-git-prevchunk) ,
  • Commands for chunks, including git.chunkInfo git.chunkStage git.chunkUndo and more.
  • Keymaps & commands for git conflicts.
  • Completion support for semantic commit.
  • Completion support for GitHub/GitLab issues.
  • Browse files changed by any commit in a read-only Commit Files TreeView.

Note for GitHub issues completion support:

  • GITHUB_API_TOKEN=xxx needs to be set in env to fetch issues from private repositories

Note for GitLab issues completion support:

  • current only API v4 support, which availabled since GitLab 9.0
  • GITLAB_PRIVATE_TOKEN=XXX needs to be set in env, check Personal access tokens
  • GitLab host needs to be set in coc-settings.json, for example "git.gitlab.hosts": ["gitlab.example.com", "gitlab.com"]

Usage

Statusline integration

  • g:coc_git_status including git branch and current project status.
  • b:coc_git_status including changed lines of current buffer.
  • b:coc_git_blame including blame info of current line.

Example for lightline user:

" lightline
let g:lightline = {
  \ 'active': {
  \   'left': [
  \     [ 'mode', 'paste' ],
  \     [ 'ctrlpmark', 'git', 'diagnostic', 'cocstatus', 'filename', 'method' ]
  \   ],
  \   'right':[
  \     [ 'filetype', 'fileencoding', 'lineinfo', 'percent' ],
  \     [ 'blame' ]
  \   ],
  \ },
  \ 'component_function': {
  \   'blame': 'LightlineGitBlame',
  \ }
\ }

function! LightlineGitBlame() abort
  let blame = get(b:, 'coc_git_blame', '')
  " return blame
  return winwidth(0) > 120 ? blame : ''
endfunction

If you're not using statusline plugin, you can add them to statusline by:

set statusline^=%{get(g:,'coc_git_status','')}%{get(b:,'coc_git_status','')}%{get(b:,'coc_git_blame','')}

User autocmd

autocmd User CocGitStatusChange {command}

Triggered after the g:coc_git_status b:coc_git_status b:coc_git_blame has changed.

Could be used for update the statusline.

Keymaps

Create keymappings like:

" navigate chunks of current buffer
nmap [g <Plug>(coc-git-prevchunk)
nmap ]g <Plug>(coc-git-nextchunk)
" navigate conflicts of current buffer
nmap [c <Plug>(coc-git-prevconflict)
nmap ]c <Plug>(coc-git-nextconflict)
" resolve the conflict under the cursor
nmap <leader>cc <Plug>(coc-git-keepcurrent)
nmap <leader>ci <Plug>(coc-git-keepincoming)
nmap <leader>cb <Plug>(coc-git-keepboth)
" show chunk diff at current position
nmap gs <Plug>(coc-git-chunkinfo)
" show commit contains current position
nmap gc <Plug>(coc-git-commit)
" show blame details for the current line
nmap gb <Plug>(coc-git-showblamedoc)
" create text object for git chunks
omap ig <Plug>(coc-git-chunk-inner)
xmap ig <Plug>(coc-git-chunk-inner)
omap ag <Plug>(coc-git-chunk-outer)
xmap ag <Plug>(coc-git-chunk-outer)

Work with git lists

To open a specified coc list, you have different ways:

  • Run :CocList and select the list by <CR>.

  • Run :CocList and type name of list for completion.

  • Create keymap for open specified list with list options, like:

    nnoremap <silent> <space>g  :<C-u>CocList --normal gstatus<CR>
    

To toggle list mode, use <C-o> and i.

To move up&down on insertmode, use <C-j> and <C-k>

To run a action, press <tab> and select the action.

Diff previews in gstatus, gfiles, commits, and bcommits use syntax folding. Move to the preview window and use zc or zM to fold file diffs, and zo or zR to expand them.

Commit Files TreeView

The commits and bcommits lists provide a changes action that opens the selected commit in the Commit Files TreeView. The existing files action continues to open the complete file snapshot through the gfiles list.

The tree compares an ordinary commit with its parent and an initial commit with the empty tree. Merge commits use the first parent by default; choose Select parent… from the root node actions to compare another parent. The root node starts expanded, and pressing <CR> on it runs Show commit. Pressing <CR> on a directory toggles it, while pressing <CR> on a file runs Show code.

Show code, Open before version, Open after version, and Open working tree file open in the editor window that was active before the TreeView. For a text file, Show code opens a read-only coc-git://<commit>/<path> buffer with buftype=nofile and detects the filetype from its path. Added lines use the DiffAdd background, and deleted lines are rendered as virtual text using DiffDelete. Deleted files open their complete parent version; binary and non-blob entries show object metadata instead of text decorations.

Use <Plug>(coc-git-nextchunk), <Plug>(coc-git-prevchunk), git.nextChunk, or git.prevChunk to navigate changed blocks in a coc-git:// buffer. The navigation wraps when Vim's wrapscan option is enabled.

When the buffer that opened the TreeView is one of the changed files, its parent directories are expanded and the file is focused. git.showCommitTree also opens that file's historical code automatically and places the cursor on the original line reported by git blame. The command reports the existing untracked or uncommitted-line warning when Git cannot associate the current line with a commit.

Use git.commitFiles.splitCommand to configure how the TreeView split opens.

Git Status TreeView

Use :CocCommand git.statusTree to display staged, unstaged, conflicted, and untracked files grouped by directory. Each file shows Git's two-column status and a readable staged/unstaged description. Press <CR> on a file to open its working-tree version in the previous editor window. For tracked files, the cursor moves to the first changed line when Git provides a diff location; otherwise it opens at line 1. Files deleted from the working tree open the read-only HEAD version through the coc-git: scheme. The root node refreshes the status snapshot. File actions follow each file's status: Add stages unstaged or untracked files, Restore staged changes unstages a file, and Restore working tree changes discards its tracked working-tree changes.

Use git.statusTree.splitCommand to configure how the TreeView split opens.

For more advance usage, checkout :h coc-list.

Issue autocomplete from multiple GitHub repositories

To enable autocompletion of issues from multiple GitHub repositories, put a comma-separated list of issue repository specifiers in the git config variable coc-git.issuesources. An issue repository specifier looks like this: github/neoclide/coc-git.

  • The first part specifies the issue provider, currently only "github" is supported
  • The second part specifies the organization or owner of the repository
  • The third part specifies the repository name

Multiple repositories can be specified using comma separation, like this: github/neoclide/coc-git,github/neoclide/coc.nvim

License

MIT

Read the complete README
  • Git extension for coc.nvim
Activation Events
  • *
Developer Resources

Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.

Open Developer Guide

Version History

Published with coc-git@2.7.15 as history.md.

Open source file

2.7.15

  • feat(lists): enable syntax folding in diff previews (af046f6)

2.7.14

  • not use sign for files not indexed (3b6f63f)

2.7.13

  • fix failure test (3cb8919)

2.7.12

  • fix: address audited git workflow issues (eb6ee85)

2.7.11

  • add AGENTS.md (34ea156)
  • feat: add git status tree view (4bc3f6e)

2.7.10

  • docs: add MIT license (172bdca)
  • feat: add commit files TreeView (189d331)

2.7.9

  • show complete commit files as decorated coc-git virtual documents with chunk navigation
  • docs: add coc-git logo (992064f)
  • feat: show staged git gutters and navigate chunks (9410092)
  • jump to the current code (641396b)
  • fix typo in warning (#222) (9317050)

2.7.8

  • add git.showCommitTree for the commit associated with the current line
  • fix historical code cursor positioning after virtual document loading
  • use node24 for CI (eacd2a2)
  • fix uuid, use commonjs version (8ab1a44)
  • fix: narrow vim call results (b72ad90)
  • fix package.json (45b1873)
  • add release.yml (3e68338)
  • fix: address audit findings (e767896)
  • feat: add git.allChunkInfo command for all chunk info (fixes #204) (43469d2)
  • feat: support configurable git blame format (fixes #127) (31e369b)
  • chore: add coc-test integration tests and upgrade toolchain (b10f485)
  • fix: correct warning message typo (PR #222) (f66c361)