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.34k stars 296 forks source link

Append key to g:gitgutter_floating_window_options #851

Closed astier closed 1 year ago

astier commented 1 year ago

What is the latest commit SHA in your installed vim-gitgutter?

edb607c

What vim/nvim version are you on?

NVIM v0.8.3

I want to modify the border of the floating window. Preferably I would simply append it to the default config like that:

let g:gitgutter_floating_window_options['border'] = 'single'

This doesn't seem to work. I solve it by redefining all keys like described in the gitgutter-documentation:

let g:gitgutter_floating_window_options = {
\ 'border': 'single',
\ 'relative': 'cursor',
\ 'row': 1,
\ 'col': 0,
\ 'width': 42,
\ 'height': &previewheight,
\ 'style': 'minimal',
\}

Is it somehow possible append keys to g:gitgutter_floating_window_options so I don't have to touch the default values and make it a little bit shorter? Thank you.

airblade commented 1 year ago

You're right, that would be much nicer.

I'll update the code when I can.

airblade commented 1 year ago

The trick here is knowing the order in which your config and plugins are loaded. Your config is read first and then the plugins. So when Vim processes your vimrc, the variable g:gitgutter_floating_window_options doesn't exist – this is why you cannot set a key/value on it.

Happily vim has a solution for this problem. After it loads plugins, it reads any config in an after/ directory. So if you create a file such as ~/.vim/after/vim-gitgutter/overrides.vim with this content:

let g:gitgutter_floating_window_options['border'] = 'single'

– you'll get the result you want.

astier commented 1 year ago

That's awesome. Somehow I didn't think of it especially since I already have a ~/.vim/after/plugin/gitgutter.vim to override some other things. Thank you!