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.12
npm package
coc-git
Requirements
coc ^0.0.82
License
MIT
Repository
GitHub
npm latest published 2026-08-24Registry checked 2026-08-24Registry summary

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.

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.12 as history.md.

Open source file

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)