gutter colors not showing change on correct line
mairs8 opened this issue · comments
What is the latest commit SHA in your installed vim-gitgutter?
67ef116
What vim/nvim version are you on?
NVIM v0.10.0-dev
I just installed git-gutter and tested it out on sample go file. Everything worked fine except it seems to highlight the wrong line with wrong colors. For instance,
line 5,6,7 were added and line 8 was changed. but it shows blue gutter on line 5 and green gutter on 6,7,8. i would expect line 8 to show blue gutter and rest to show green.
Am i missing something?
lines 5,6,7 added and line 8 changed.
git-gutter.lua
return {
"airblade/vim-gitgutter",
config = function()
vim.opt.signcolumn = "yes:1"
vim.opt.numberwidth = 3
vim.g.gitgutter_sign_added = "+"
vim.g.gitgutter_sign_modified = "~"
vim.g.gitgutter_sign_removed = "-"
end,
}
I agree that it doesn't show what you would expect. It's a consequence of the way git-diff works.
If you diff your file on the command line, you'll get something like this:
$ git diff -U0
diff --git i/path/to/file.go w/path/to/file.go
index <sha>..<sha> 100644
--- i/path/to/file.go
+++ i/path/to/file.go
@@ -5 -5,4 @@ func main()
- c := a + b
+ string1 := "hddi"
+ string2 := "bye"
+ fmt.Printf("%d, %d", string1, string2)
+ c := a + b+ 4
The hunk header (@@ -5 -5+4 @@
) says that 1 line was removed and 4 lines were added. We can infer that 1 line was changed and 3 were added, but not which line was which.
When a hunk contains modifications and additions, gitgutter assumes that the modifications come first – there's nothing else it can do.