Skip to content

Commit fb401c7

Browse files
Merge pull request #1 from ryutaro-asada/feature/vscode
vscode_like diff
2 parents a3b7152 + fe9dafb commit fb401c7

File tree

6 files changed

+753
-53
lines changed

6 files changed

+753
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,132 @@
11
# partial-diff.nvim
22

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.
54

5+
## Features
6+
7+
- 🎯 **Partial Diff**: Compare any two selected regions of code
8+
9+
## Demo
610

711
https://github.com/ryutaro-asada/partial-diff.nvim/assets/58899265/6eaae6a9-2ecb-489e-8d38-c4bd9ff41690
812

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+
```
955

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.
1065

1166
## Commands
1267

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
1684

1785
## Usage
1886

19-
Follow the steps below to use these commands:
87+
### Basic Workflow
2088

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
2694

27-
```vim
28-
:'<,'>PartialDiffA
29-
:'<,'>PartialDiffB
30-
```
95+
### Example
3196

32-
To delete the current diff, use the `PartialDiffDelete` command.
97+
```vim
98+
" Select lines 10-20 in visual mode
99+
:'<,'>PartialDiffFrom
33100
101+
" Select lines 30-40 in visual mode
102+
:'<,'>PartialDiffTo
34103
35-
## Installation
104+
" Close the diff when done
105+
:PartialDiffDelete
106+
```
36107

37-
Using [lazy.nvim](https://github.com/folke/lazy.nvim)
108+
## Configuration
38109

39110
```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+
})
43115
```
44116

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+
45126
## Contributing
46127

47128
If you have any suggestions or improvements, feel free to open an issue or submit a pull request.
48129

49130
## License
50131

51132
This project is licensed under the MIT License.
52-

0 commit comments

Comments
 (0)