Skip to content
프로젝트

akinsho/git-conflict.nvim

GitHub에서 보기

소개

Neovim에서 병합 충돌을 시각화하고 해결하는 플러그인

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
+1
in 7 days
+2
in 15 days
+3
in 1 month
+3

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

git-conflict.nvim

https://user-images.githubusercontent.com/22454918/159362564-a66d8c23-f7dc-4d1d-8e88-c5c73a49047e.mov

A plugin to visualise and resolve conflicts in neovim. This plugin was inspired by conflict-marker.vim

Status

This plugin is under active development, it should generally work, but you're likely to encounter some bugs during usage.

Requirements

  • git
  • nvim 0.7+

Installation

-- packer.nvim
use {'akinsho/git-conflict.nvim', tag = "*", config = function()
  require('git-conflict').setup()
end}

-- lazy.nvim
{'akinsho/git-conflict.nvim', version = "*", config = true}

I recommend using the {tag|version} field of your package manager, so your version of this plugin is only updated when a new tag is pushed as main itself might be unstable.

Configuration

{
  default_mappings = true, -- disable buffer local mapping created by this plugin
  default_commands = true, -- disable commands created by this plugin
  disable_diagnostics = false, -- This will disable the diagnostics in a buffer whilst it is conflicted
  list_opener = 'copen', -- command or function to open the conflicts list
  highlights = { -- They must have background color, otherwise the default color will be used
    incoming = 'DiffAdd',
    current = 'DiffText',
  }
}

Commands

  • GitConflictChooseOurs — Select the current changes.
  • GitConflictChooseTheirs — Select the incoming changes.
  • GitConflictChooseBoth — Select both changes.
  • GitConflictChooseNone — Select none of the changes.
  • GitConflictNextConflict — Move to the next conflict.
  • GitConflictPrevConflict — Move to the previous conflict.
  • GitConflictListQf — Get all conflict to quickfix

Listing conflicts

You can list conflicts in the quick fix list using the GitConflictListQf command

Screen Shot 2022-03-27 at 12 03 43

quickfix displayed using nvim-pqf

Autocommands

When a conflict is detected by this plugin a User autocommand is fired called GitConflictDetected. When this is resolved another command is fired called GitConflictResolved.

Either of these can be used to run logic whilst dealing with conflicts e.g.

vim.api.nvim_create_autocmd('User', {
  pattern = 'GitConflictDetected',
  callback = function()
    vim.notify('Conflict detected in '..vim.fn.expand('<afile>'))
    vim.keymap.set('n', 'cww', function()
      engage.conflict_buster()
      create_buffer_local_mappings()
    end)
  end
})

Mappings

This plugin offers default buffer local mappings inside conflicted files. This is primarily because applying these mappings only to relevant buffers is impossible through global mappings. A user can however disable these by setting default_mappings = false anyway and create global mappings as shown below. The default mappings are:

  • co — choose ours
  • ct — choose theirs
  • cb — choose both
  • c0 — choose none
  • ]x — move to previous conflict
  • [x — move to next conflict

If you would rather not use these then you can specify your own mappings.

require'git-conflict'.setup {
  default_mappings = {
    ours = 'o',
    theirs = 't',
    none = '0',
    both = 'b',
    next = 'n',
    prev = 'p',
  },
}

or alternatively, set default_mappings = false and apply the mappings yourself

example manual mappings
vim.keymap.set('n', 'co', '<Plug>(git-conflict-ours)')
vim.keymap.set('n', 'ct', '<Plug>(git-conflict-theirs)')
vim.keymap.set('n', 'cb', '<Plug>(git-conflict-both)')
vim.keymap.set('n', 'c0', '<Plug>(git-conflict-none)')
vim.keymap.set('n', '[x', '<Plug>(git-conflict-prev-conflict)')
vim.keymap.set('n', ']x', '<Plug>(git-conflict-next-conflict)')

API

This plugin exposes an API to extract some of the data it collects for other purposes.

conflict_count({bufnr})
    Returns the amount of conflicts in a given buffer.
    

    Parameters:
	{bufnr} (number) Specify the buffer for which you want to know the
	                 amount of conflicts (default: current buffer).

    Return:
	number: The amount of conflicts.

Issues

Please read this — This plugin is not intended to do anything other than provide fancy visuals, and some mappings to handle conflict resolution It will not be expanded to become a full git management plugin, there are a zillion plugins that do that already, this won't be one of those.

Feature requests

Open source should be collaborative, if you have an idea for a feature you'd like to see added. Submit a PR rather than a feature request.

관련 프로젝트 살펴보기

불러오는 중…