airblade / vim-gitgutter

A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
MIT License
8.35k stars 296 forks source link

Preview Window is messed up (Too long?) #708

Closed qazip closed 4 years ago

qazip commented 4 years ago

What is the latest commit SHA in your installed vim-gitgutter? How do I check that? I have it installed with VimPlug and just recently did an update, so it is the latest version.

What vim/nvim version are you on? NVIM v0.5.0-447-g8745247cb

When doing GitGutterPreviewHunk on a changed hunk, I should be able to see the whole line so I am able to see the changes. This is not true, the line gets cut-off before the changes are actually shown. This is for a long (markdown) line, however.

Would it be possible to show the preview-window in a new window and not as a popup/floating? Or just show it as actual text, like sublime-text does?

EDIT: I've tried adding let g:gitgutter_preview_win_location = 'bel' (or 'abo' or 'to') to my init.vim but nothing changes..

airblade commented 4 years ago

You can do let g:gitgutter_preview_win_floating = 0 to see the diff in a "normal" preview window rather than a floating one.

qazip commented 4 years ago

Ah, cool! How do I change the height of this new window? Any option for that?

airblade commented 4 years ago

With Vim's previewheight option.

qazip commented 4 years ago

Weirdly enough, set previewheight=50 (or any other value) doesn't change anything. But alright, this is now a (neo)vim issue! Thanks @airblade !

airblade commented 4 years ago

More specifically, the preview window's height is set to the smaller of the diff's height and &previewheight.

https://github.com/airblade/vim-gitgutter/blob/b356cc9a7da08ebeb919cd04b2831dad71a34d38/autoload/gitgutter/hunk.vim#L463

https://github.com/airblade/vim-gitgutter/blob/b356cc9a7da08ebeb919cd04b2831dad71a34d38/autoload/gitgutter/hunk.vim#L499

qazip commented 4 years ago

Hey @airblade, sorry for bothering you again!

I haven't been able to fix this. Doing "set previewheight = 30" (or whatever number) doesn't seem to help, so I guess it is being decided by the "diff's height". How would I change that?

airblade commented 4 years ago

I'm not sure what you're trying to fix. Are you trying to get the preview window to always be 50 (or 30 or whatever you set) lines high, even if the diff it's showing is only 10 lines?

If so, there's no built-in way to change that. If previewheight is 50 and the diff is 10 lines long, the preview window will be 10 lines high. If the diff is 60 lines long, the preview window will be 50 lines high.

The only way to change this is to comment out line 499 linked above in your copy of vim-gitgutter.

qazip commented 4 years ago

Well, I would like the preview-window to show the whole difference. Here is my use case:

It will only show 2 lines, so it will only show the red and not the green. I would like to see the red and the green at the same time. This works if the changed sentence/hunk is only 1 line long. If the hunk is more than 2 lines, then it won't even show the whole hunk as red, and so I have to scroll down to see the whole thing..

EDIT: This happens regardless of using preview window or preview floating. The diff is always 2 lines long and so it doesn't show the whole thing..

airblade commented 4 years ago

What is your previewheight value? :echo &previewheight

qazip commented 4 years ago

set previewheight=30

airblade commented 4 years ago

Please can you send me a screenshot of the situation you described just above? I'm not 100% sure I understand what you're seeing.

qazip commented 4 years ago

Sure. First picture shows that it is only showing 2 lines. Second picture shows the whole hunk with "Git diff" from Vim-Fugitire.

gitgutter1

gitgutter2

airblade commented 4 years ago

Ah, I see now. Thanks for the screenshots.

So the preview window's height is based on screen lines, not "real" lines. I'll come up with a fix...