|
1 | 1 | # partial-diff.nvim |
2 | 2 |
|
3 | | -This repository contains a set of commands for Neovim that allow you to perform partial diffs on your code. |
4 | | -## demo |
| 3 | +A Neovim plugin for performing partial diffs on selected code regions with advanced character-level diff highlighting powered by VSCode's diff algorithm. |
5 | 4 |
|
| 5 | +## Features |
| 6 | + |
| 7 | +- 🎯 **Partial Diff**: Compare any two selected regions of code |
| 8 | + |
| 9 | +## Demo |
6 | 10 |
|
7 | 11 | https://github.com/ryutaro-asada/partial-diff.nvim/assets/58899265/6eaae6a9-2ecb-489e-8d38-c4bd9ff41690 |
8 | 12 |
|
| 13 | +## Installation |
| 14 | + |
| 15 | +### Using [lazy.nvim](https://github.com/folke/lazy.nvim) |
| 16 | + |
| 17 | +```lua |
| 18 | + { |
| 19 | + "ryutaro-asada/partial-diff.nvim", |
| 20 | + }, |
| 21 | +``` |
| 22 | + |
| 23 | +### configuration |
| 24 | + |
| 25 | +```lua |
| 26 | +require('partial-diff').setup({ |
| 27 | + -- Debug options |
| 28 | + debug = false, |
| 29 | + -- Highlight customization |
| 30 | + highlights = { |
| 31 | + -- Link to existing highlight groups |
| 32 | + line_change = 'DiffChange', |
| 33 | + line_add = 'DiffAdd', |
| 34 | + line_delete = 'DiffDelete', |
| 35 | + -- Specify custom colors |
| 36 | + char_add = { |
| 37 | + bg = '#2d5a2d', -- Background color |
| 38 | + fg = '#a9dc76', -- Foreground color |
| 39 | + bold = true, -- Bold |
| 40 | + italic = false, -- Italic |
| 41 | + underline = false -- Underline |
| 42 | + }, |
| 43 | + char_delete = { |
| 44 | + bg = '#5a2d2d', |
| 45 | + fg = '#ff6188', |
| 46 | + }, |
| 47 | + char_change = { |
| 48 | + bg = '#4a4a0e', |
| 49 | + fg = '#ffd866', |
| 50 | + bold = true |
| 51 | + } |
| 52 | + } |
| 53 | +}) |
| 54 | +``` |
9 | 55 |
|
| 56 | +### VSCode Diff Algorithm (Optional but Recommended) |
| 57 | + |
| 58 | +For better character-level diff highlighting, install the VSCode diff algorithm: |
| 59 | + |
| 60 | +1. Ensure Node.js is installed on your system |
| 61 | +2. Run `:PartialDiffInstallVSCode` in Neovim |
| 62 | +3. This will install the required npm packages in the plugin directory |
| 63 | + |
| 64 | +Without this, the plugin will fall back to Neovim's built-in diff. |
10 | 65 |
|
11 | 66 | ## Commands |
12 | 67 |
|
13 | | -- `PartialDiffA`: Marks a range of lines as the first part of the diff. |
14 | | -- `PartialDiffB`: Marks a range of lines as the second part of the diff. |
15 | | -- `PartialDiffDelete`: Deletes the current partial diff. |
| 68 | +### Primary Commands |
| 69 | + |
| 70 | +- `:PartialDiffFrom` - Mark a range of lines as the source (what you're diffing from) |
| 71 | +- `:PartialDiffTo` - Mark a range of lines as the target (what you're diffing to) and display the diff |
| 72 | +- `:PartialDiffDelete` - Close the current diff view |
| 73 | +- `:PartialDiffInstallVSCode` - Install VSCode diff algorithm dependencies |
| 74 | + |
| 75 | +### Legacy Commands (Backward Compatibility) |
| 76 | + |
| 77 | +- `:PartialDiffA` - Alias for `:PartialDiffFrom` |
| 78 | +- `:PartialDiffB` - Alias for `:PartialDiffTo` |
| 79 | + |
| 80 | +### Debug Commands |
| 81 | + |
| 82 | +- `:PartialDiffShowLog` - Show the debug log file |
| 83 | +- `:PartialDiffClearLog` - Clear the debug log file |
16 | 84 |
|
17 | 85 | ## Usage |
18 | 86 |
|
19 | | -Follow the steps below to use these commands: |
| 87 | +### Basic Workflow |
20 | 88 |
|
21 | | -1. Select the range of lines with visual mode. |
22 | | -2. Type `:PartialDiffA`. |
23 | | -3. Select another range of lines with visual mode. |
24 | | -4. Type `:PartialDiffB`. |
25 | | -5. View the diff. |
| 89 | +1. Select the first range of lines in visual mode |
| 90 | +2. Execute `:PartialDiffFrom` (or use your keymap) |
| 91 | +3. Select the second range of lines in visual mode |
| 92 | +4. Execute `:PartialDiffTo` (or use your keymap) |
| 93 | +5. View the diff in a new tab with side-by-side comparison |
26 | 94 |
|
27 | | -```vim |
28 | | -:'<,'>PartialDiffA |
29 | | -:'<,'>PartialDiffB |
30 | | -``` |
| 95 | +### Example |
31 | 96 |
|
32 | | -To delete the current diff, use the `PartialDiffDelete` command. |
| 97 | +```vim |
| 98 | +" Select lines 10-20 in visual mode |
| 99 | +:'<,'>PartialDiffFrom |
33 | 100 |
|
| 101 | +" Select lines 30-40 in visual mode |
| 102 | +:'<,'>PartialDiffTo |
34 | 103 |
|
35 | | -## Installation |
| 104 | +" Close the diff when done |
| 105 | +:PartialDiffDelete |
| 106 | +``` |
36 | 107 |
|
37 | | -Using [lazy.nvim](https://github.com/folke/lazy.nvim) |
| 108 | +## Configuration |
38 | 109 |
|
39 | 110 | ```lua |
40 | | - { |
41 | | - "ryutaro-asada/partial-diff.nvim", |
42 | | - }, |
| 111 | +require("partial-diff").setup({ |
| 112 | + debug = false, -- Enable debug logging |
| 113 | + log_file_path = vim.fn.stdpath('cache') .. '/partial-diff.log', -- Custom log path |
| 114 | +}) |
43 | 115 | ``` |
44 | 116 |
|
| 117 | +## Powered By |
| 118 | + |
| 119 | +- [vscode-diff](https://github.com/micnil/vscode-diff) - Advanced character-level diff computation |
| 120 | + |
| 121 | +## Requirements |
| 122 | + |
| 123 | +- Neovim 0.10.0 or later |
| 124 | +- (Optional) Node.js for VSCode diff algorithm |
| 125 | + |
45 | 126 | ## Contributing |
46 | 127 |
|
47 | 128 | If you have any suggestions or improvements, feel free to open an issue or submit a pull request. |
48 | 129 |
|
49 | 130 | ## License |
50 | 131 |
|
51 | 132 | This project is licensed under the MIT License. |
52 | | - |
|
0 commit comments