• Stars
    star
    981
  • Rank 46,671 (Top 1.0 %)
  • Language
    Lua
  • Created over 2 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A plugin to visualise and resolve merge conflicts in neovim

git-conflict.nvim

git-conflict.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
  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_autocommand('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)')

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.

More Repositories

1

toggleterm.nvim

A neovim lua plugin to help easily manage multiple terminal windows
Lua
4,352
star
2

bufferline.nvim

A snazzy bufferline for Neovim
Lua
3,497
star
3

flutter-tools.nvim

Tools to help create flutter apps in neovim using the native lsp
Lua
987
star
4

dotfiles

🏡 dotfiles
Lua
235
star
5

org-bullets.nvim

Lua
113
star
6

horizon.nvim

Horizon Theme - Neovim Edition 🌅
Lua
45
star
7

dependency-assist.nvim

A neovim plugin to help find/search for dependency information/versions
Lua
44
star
8

pubspec-assist.nvim

Lua
25
star
9

gitgazer

A CLI app that lets you keep track of developments in your favourite repos on Github
Go
11
star
10

clock.nvim

A neovim plugin to show a timer in a floating window
Lua
10
star
11

oni-theme-night-owl

Night Owl - Onivim Editor theme
Vim Script
6
star
12

algorhythms

Rust
3
star
13

portfolio

Personal Portfolio aka the doings
OCaml
3
star
14

react-event-planner

⏰⏳ React to Time
JavaScript
2
star
15

phoenix-kitty

A go script to save the current kitty state to a session file
Go
2
star
16

vim-dune

Syntax File for Dune
Vim Script
2
star
17

Oni_the_guification_of_neovim

Vim Conf 18 Talk Slides
JavaScript
2
star
18

postgres-workshop

Postgres Workshop
JavaScript
2
star
19

go-game-of-life

The Game of Life in Go using the Ebiten library
Go
2
star
20

gopher

Go
1
star
21

Monzoid

JavaScript
1
star
22

express-handlebars-week

1
star
23

oni-plugin-eslint

An ESLint plugin for Oni vim
JavaScript
1
star
24

clojure-counter

A Stunningly simplistic clojure counter and clock
Clojure
1
star
25

Tips-and-Tricks

A repository of aforementioned tips and tricks
1
star
26

Akins-Pocket

My Bespoke Version of Pocket
JavaScript
1
star
27

lightline-statuslinetabs

A Vim plugin to show tabs in the Lightline Statusline
Vim Script
1
star
28

game-of-life

James Conway's Game of Life [WIP!!]
JavaScript
1
star
29

human-phenotype-challenge

A Visualisation of the Human Phenotype Ontology
JavaScript
1
star
30

week8-PA-Github-pajes

The real Github Pajes the other fork is unauthorised, okay thanks
JavaScript
1
star
31

all-of-fac

An App designed with React to visualise all the members of Founders and Coders
JavaScript
1
star
32

rota-app

Scheduling and rota management React app
JavaScript
1
star
33

ctrl-grp-api

An NodeJS API for the ctrl-grp challenge (link to demo ->)
JavaScript
1
star