Skip to content

TheMusicBoy/diffui.nvim

Repository files navigation

DiffUI.nvim

A powerful Neovim plugin for handling diffs and resolving git conflicts with an intuitive UI.

Features

  • 🔀 Git Conflict Resolution: Easily resolve merge conflicts with intuitive keybindings
  • 📊 Diff Overlay: View and apply changes with inline or split diff views
  • 🤝 CodeCompanion Integration: Seamlessly integrates with CodeCompanion.nvim
  • Fast and Lightweight: Built with performance in mind
  • 🎨 Customizable: Flexible configuration and theming

Installation

Using lazy.nvim

{
  "painfire/diffui.nvim",
  dependencies = {
    "nvim-lua/plenary.nvim",
  },
  config = function()
    require("diffui").setup({
      -- Your configuration here
    })
  end,
}
use {
  "painfire/diffui.nvim",
  requires = { "nvim-lua/plenary.nvim" },
  config = function()
    require("diffui").setup()
  end
}

Configuration

Default configuration:

require("diffui").setup({
  -- Git conflict resolution
  conflict = {
    enabled = true,
    keymaps = {
      choose_ours = "co",
      choose_theirs = "ct",
      choose_both = "cb",
      choose_none = "c0",
      next_conflict = "]x",
      prev_conflict = "[x",
    },
    highlights = {
      current = "DiffAdd",
      incoming = "DiffChange",
      ancestor = "DiffDelete",
    },
  },
  
  -- Diff viewing and editing
  diff = {
    enabled = true,
    provider = "internal",
    keymaps = {
      apply = "<leader>da",
      reject = "<leader>dr",
      next_hunk = "]c",
      prev_hunk = "[c",
      toggle_overlay = "<leader>do",
    },
    overlay = {
      style = "inline", -- "inline" or "split"
      position = "right",
    },
  },
  
  -- CodeCompanion integration
  codecompanion = {
    enabled = true,
    auto_attach = true,
    show_diff_on_apply = true,
  },
  
  -- UI settings
  ui = {
    border = "rounded",
    winblend = 0,
    signs = {
      add = "",
      change = "",
      delete = "_",
      topdelete = "",
      changedelete = "~",
    },
  },
})

Usage

Git Conflict Resolution

When you open a file with git conflicts, DiffUI will automatically detect and highlight them:

  • co - Choose ours (current branch)
  • ct - Choose theirs (incoming branch)
  • cb - Choose both versions
  • c0 - Choose none (delete conflict)
  • ]x - Jump to next conflict
  • [x - Jump to previous conflict

Diff Viewing

Toggle diff overlay:

:DiffUiToggle

Or use the keymap: <leader>do

Apply/reject hunks:

  • <leader>da - Apply current hunk
  • <leader>dr - Reject current hunk

CodeCompanion Integration

When CodeCompanion makes changes to your buffer, DiffUI automatically tracks the original content and shows a diff overlay when done (if show_diff_on_apply is enabled).

Commands

  • :DiffUiConflictChooseOurs - Choose our version in conflict
  • :DiffUiConflictChooseTheirs - Choose their version in conflict
  • :DiffUiConflictChooseBoth - Choose both versions
  • :DiffUiConflictNext - Jump to next conflict
  • :DiffUiConflictPrev - Jump to previous conflict
  • :DiffUiToggle - Toggle diff overlay
  • :DiffUiApply - Apply current hunk
  • :DiffUiReject - Reject current hunk

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published