
Git extension for coc.nvim
Published Package Summary
coc-git
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, by
b:coc_git_status. - Git status of current line, by
b:coc_git_blamefor statusline, andaddGBlameToVirtualTextfor 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.chunkInfogit.chunkStagegit.chunkUndoand 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 FilesTreeView.
Note for GitHub issues completion support:
GITHUB_API_TOKEN=xxxneeds to be set in env to fetch issues from private repositories
Note for GitLab issues completion support:
- current only API
v4support, which availabled since GitLab 9.0 GITLAB_PRIVATE_TOKEN=XXXneeds 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_statusincluding git branch and current project status.b:coc_git_statusincluding changed lines of current buffer.b:coc_git_blameincluding 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
:CocListand select the list by<CR>. -
Run
:CocListand 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
- Git extension for coc.nvim
- *
Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.
Open Developer GuideVersion History
Published with coc-git@2.7.12 as history.md.
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)
Contributed Commands
All contributes.commands entries from the published package manifest for coc-git@2.7.12.
| Command (:CocCommand) | Description |
|---|---|
| git.refresh | Refresh git information for all buffers. |
| git.statusTree | Open changed files from Git status in a TreeView. |
| git.nextChunk | Navigate to the next changed chunk. |
| git.prevChunk | Navigate to the previous changed chunk. |
| git.keepCurrent | Keep the current part of the merge conflict. |
| git.keepIncoming | Keep the incoming part of the merge conflict. |
| git.keepBoth | Keep both parts of the merge conflict. |
| git.chunkInfo | Show chunk info under cursor |
| git.allChunkInfo | Return all changed chunks in the current buffer. |
| git.chunkStage | Stage current chunk. |
| git.chunkUnstage | Unstage chunk that contains current line |
| git.chunkUndo | Undo current chunk. |
| git.showCommit | Show commit of current chunk. |
| git.showCommitTree | Show commit of current line in TreeView. |
| git.browserOpen | Open current line in browser, github url supported. |
| git.copyUrl | Copy url of current line to clipboard, github url supported. |
| git.copyPermalink | Copy permalink of current line to clipboard, github url supported. |
| git.diffCached | Show cached diff in preview window. |
| git.foldUnchanged | Fold unchanged lines of current buffer. |
| git.toggleGutters | Toggle git gutters in sign column. |
| git.push | Push code of current branch to remote |
| git.showBlameDoc | Show git blame info in float or popup window |
Configuration Schema
All contributes.configuration entries from the published package manifest, including each raw property schema for coc-settings.json.
Raw JSON Schema
{
"type": "object",
"scope": "application",
"format": "{\"git-service-1's domain\":[\"fix-for-normal-url\",\"fix-for-permalink\"],\"git-service-2's domain\":...}",
"default": {},
"examples": [
{
"gitea.com": [
"blob|src/branch",
"blob|src/commit"
],
"gitlab.org": [
"blob|-/blob",
"blob|-/blob"
],
"gerrit.with.gitiles": [
"(.*)/a/(.*)/blob/(.*)#L(.*)|$1/plugins/gitiles/$2/+/refs/heads/$3#$4",
"(.*)/a/(.*)/blob/(.*)#L(.*)|$1/plugins/gitiles/$2/+/$3#$4"
]
}
],
"description": "A fix is a string, like \"pattern|replacement\" show in examples sessions, use to transform github style url to whatever you like. copyUrl will run url.replace(pattern,replacement) after generate a github style url. Example configuration make browserOpen and copyUrl work with gitlab, gitea and gerrit with gitiles."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "git",
"description": "Command for git, could be absolute path of git executable."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "origin",
"description": "Remote name for fetch github issues."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "(%a %t) %s",
"description": "Format of git blame virtual text. Supported placeholders: %a author, %t time, %s summary, %S short sha, %% literal percent."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"scope": "window",
"default": [],
"description": "Options for git diff command, eg: [\"--ignore-all-space\"]"
}Raw JSON Schema
{
"type": "object",
"scope": "application",
"default": {},
"properties": {
"close": {
"type": "boolean",
"default": false,
"description": "Set to true to draw close icon"
},
"title": {
"type": "string",
"default": "",
"description": "Title used by float window."
},
"border": {
"type": "boolean",
"default": false,
"description": "Set to true to use borders."
},
"shadow": {
"type": "boolean",
"default": false,
"description": "Drop shadow effect by blending with the background, neovim only."
},
"rounded": {
"type": "boolean",
"default": false,
"description": "Use rounded borders when border is true."
},
"maxWidth": {
"type": "integer",
"description": "Maximum width of float window, include border."
},
"winblend": {
"type": "integer",
"default": 0,
"maximum": 100,
"minimum": 0,
"description": "Enables pseudo-transparency by set 'winblend' option of window, neovim only."
},
"focusable": {
"type": "boolean",
"default": true,
"description": "Enable focus by user actions (wincmds, mouse events), neovim only."
},
"highlight": {
"type": "string",
"default": "CocFloating",
"description": "Background highlight group of float window."
},
"maxHeight": {
"type": "integer",
"minimum": 2,
"description": "Maximum height of float window, include border."
},
"borderhighlight": {
"type": "string",
"default": "CocFloating",
"description": "Border highlight group of float window."
}
},
"description": "Configure style of float window/popup, extends from floatFactory.floatConfig",
"additionalProperties": false
}Raw JSON Schema
{
"type": "number",
"scope": "window",
"default": 0,
"description": "Line count to leave below and above the fold."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "#%i",
"description": "Formatting string for issue completion. Supported interpolation variables: %i - issue id. %r - repository name. %o - organization/owner name. %t - issue title. %b - issue body. %c - issue created at. %a - issue author. %u - issue url."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "",
"description": "Revision used as the gutter diff base, default is the current index."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"scope": "window",
"default": [
"gitlab.com"
],
"description": "Custom GitLab hosts"
}Raw JSON Schema
{
"type": "number",
"scope": "application",
"default": 10,
"description": "Priority of sign gutters, default to 10."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "Enable gutters in sign column."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"scope": "window",
"default": [],
"description": "Default arguments used for the git.push command, ex: [\"--force-with-lease\"]"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "+",
"description": "Text of added sign."
}Raw JSON Schema
{
"type": "string",
"default": "┋"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "",
"description": "Branch character used with g:coc_git_status"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "Update gutters in realtime, default: true."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "●",
"description": "Git staged decorator used with g:coc_git_status"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "use real time in git blame info"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "*",
"description": "Git changed decorator used with g:coc_git_status"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "~",
"description": "Text of changed sign."
}Raw JSON Schema
{
"type": "boolean",
"scope": "application",
"default": true,
"description": "Enable highlight conflict lines."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "_",
"description": "Text of removed sign."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffAdd",
"description": "Highlight group for added sign."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "",
"description": "Branch name for browserOpen and copyUrl."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "",
"description": "Remote name for browserOpen and copyUrl."
}Raw JSON Schema
{
"type": "string",
"default": "CocGitMixed"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": " ",
"description": "Prefix of git blame information to virtual text, require virtual text feature of vim/neovim."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "Enable global g:coc_git_status."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "above sp",
"description": "Command used when split new window for show commit."
}Raw JSON Schema
{
"type": "number",
"scope": "window",
"default": 9,
"description": "Priority of staged gutter signs."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "…",
"description": "Git untracked decorator used with g:coc_git_status"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffChange",
"description": "Highlight group for changed sign."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "x",
"description": "Git conflicted decorator used with g:coc_git_status"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Show staged changes in the sign column."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffDelete",
"description": "Highlight group for removed sign."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "‾",
"description": "Text of top removed sign."
}Raw JSON Schema
{
"type": "boolean",
"scope": "application",
"default": true
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Add git blame information to b:coc_git_blame."
}Raw JSON Schema
{
"type": "boolean",
"scope": "application",
"default": true,
"description": "Commit message with scope field"
}Raw JSON Schema
{
"type": "boolean",
"scope": "application",
"default": false,
"description": "Show commit in floating or popup window"
}Raw JSON Schema
{
"type": "string",
"default": "┃"
}Raw JSON Schema
{
"type": "integer",
"scope": "application",
"default": 99
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "[I]"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Add git blame information to virtual text, require virtual text feature of vim/neovim."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "≃",
"description": "Text of change removed sign."
}Raw JSON Schema
{
"type": "boolean",
"scope": "application",
"default": false,
"description": "Auto save opened files before open list."
}Raw JSON Schema
{
"type": "string",
"default": "┃"
}Raw JSON Schema
{
"type": "string",
"default": "╻"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffDelete",
"description": "Highlight group for top removed sign."
}Raw JSON Schema
{
"type": [
"array",
"null"
],
"items": {
"type": "string"
},
"scope": "application",
"default": [
"gitcommit",
"gina-commit"
],
"description": "Enabled filetypes"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffText",
"description": "Highlight group for the merged common ancestors highlight group."
}Raw JSON Schema
{
"type": "string",
"default": "CocGitStagedAdd"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "belowright 40vs",
"description": "Command used to open the Git status TreeView."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "belowright 40vs",
"description": "Command used to open the changed-files TreeView for a commit."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffChange",
"description": "Highlight group for the current version of a merge conflict."
}Raw JSON Schema
{
"type": [
"array",
"null"
],
"items": {
"type": "string"
},
"scope": "application",
"default": [
"gitcommit",
"gina-commit"
],
"description": "Enabled filetypes"
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffChange",
"description": "Highlight group for change removed sign."
}Raw JSON Schema
{
"type": "string",
"scope": "application",
"default": "DiffAdd",
"description": "Highlight group for the incoming version of a merge conflict."
}Raw JSON Schema
{
"type": "string",
"default": "CocGitStagedChange"
}Raw JSON Schema
{
"type": "string",
"default": "CocGitStagedDelete"
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"scope": "application",
"default": [
"#"
]
}