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.38k stars 297 forks source link

Prev/next hunk mappings not working in init.vim #776

Closed farbodsz closed 3 years ago

farbodsz commented 3 years ago

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

24cc47789557827209add5881c226243711475ce

What vim/nvim version are you on?

NVIM v0.4.4


Summary

My issue is about <Plug>(GitGutterPrevHunk)/<Plug>(GitGutterNextHunk) mappings not working in init.vim, although they do work when opening a symlink to init.vim.

My setup

In my Neovim configuration, I have sym-linked files in the ~/.config/nvim directory to ~/.dotfiles/neovim/.config/nvim. My .dotfiles directory is a git repo (can be found here if needed):

~/.config/nvim$ ls -l
total 36
lrwxrwxrwx  1 farbod farbod   43 Nov 30 15:44 ale.vim -> ../../.dotfiles/neovim/.config/nvim/ale.vim
drwxrwxr-x  2 farbod farbod 4096 Mar 24 18:05 bin
lrwxrwxrwx  1 farbod farbod   53 Aug 30  2020 coc-settings.json -> ../../.dotfiles/neovim/.config/nvim/coc-settings.json
lrwxrwxrwx  1 farbod farbod   43 Oct  9 11:34 coc.vim -> ../../.dotfiles/neovim/.config/nvim/coc.vim
lrwxrwxrwx  1 farbod farbod   48 Mar 16 15:38 fugitive.vim -> ../../.dotfiles/neovim/.config/nvim/fugitive.vim
lrwxrwxrwx  1 farbod farbod   43 Nov 30 15:44 fzf.vim -> ../../.dotfiles/neovim/.config/nvim/fzf.vim
lrwxrwxrwx  1 farbod farbod   49 Nov 30 15:44 gitgutter.vim -> ../../.dotfiles/neovim/.config/nvim/gitgutter.vim
lrwxrwxrwx  1 farbod farbod   44 Aug 30  2020 init.vim -> ../../.dotfiles/neovim/.config/nvim/init.vim
drwxr-xr-x  2 farbod farbod 4096 Jul 30  2020 pack
drwxr-xr-x 36 farbod farbod 4096 Apr  5 11:40 plugged
drwxr-xr-x  2 farbod farbod 4096 Feb  5 18:19 spell
drwxrwxr-x  2 farbod farbod 4096 Mar 24 18:53 syntax
lrwxrwxrwx  1 farbod farbod   45 Oct  9 11:34 theme.vim -> ../../.dotfiles/neovim/.config/nvim/theme.vim
drwxrwxr-x  2 farbod farbod 4096 Apr  2 11:36 UltiSnips

I also have the following gitgutter configuration:

let g:gitgutter_map_keys = 0

nmap ]h <Plug>(GitGutterNextHunk)
nmap [h <Plug>(GitGutterPrevHunk)

nmap <leader>hs <Plug>(GitGutterStageHunk)
" etc...

The issue

If I cd into the .config/nvim directory and open init.vim (a symlink), I am able to use my [h and ]h mappings to navigate hunks. Gitgutter works great here.

However, if I open init.vim from .dotfiles/neovim/.config/nvim, using the hunk mappings does nothing (no message at the bottom either - it's as if they weren't mapped). Both maps are set though - running :map [h returned:

n   [h            <Plug>(GitGutterPrevHunk)

What is working

After opening init.vim from .dotfiles (not the symlink)...

nmap ]h :GitGutterNextHunk<cr>
nmap [h :GitGutterPrevHunk<cr>
airblade commented 3 years ago

init.vim from .dotfiles seems to be the only affected file

How strange. Please could you tell me what :echo gitgutter#utility#is_active(bufnr('')) produces when you have this file open?

farbodsz commented 3 years ago

Please could you tell me what :echo gitgutter#utility#is_active(bufnr('')) produces when you have this file open?

It outputs 1 (which is the same output I get as for the files that don't display this issue)

airblade commented 3 years ago

Thanks. I have no idea what's wrong so perhaps you could turn on logging (let g:gitgutter_log=1), reproduce the problem, then post the file gitgutter.log which will be in gitgutter's directory.

farbodsz commented 3 years ago

Okay thanks - I've produced the gitgutter.log file.

I opened up files 3 times:

  1. Opened init.vim from the .config folder (symlink)
  2. Opened init.vim from my .dotfiles folder
  3. Opened another vim file from the .dotfiles folder
airblade commented 3 years ago

I see you use mkview and loadview, which can cause surprising behaviour if you change a mapping.

Please could you delete any view file for your non-symlinked init.vim and try again?

farbodsz commented 3 years ago

Yep, removing mkview and loadview fixed the problem!

I'll probably just remove them from my init.vim since I don't need my remember_folds autogroup that much anyway.

Thanks!

airblade commented 3 years ago

Great!