vifm / vifm.vim

Vim plugin that allows use of vifm as a file picker
325 stars 18 forks source link

vifm doesn't work well with gitgutter. fails to open files from untracked file. #80

Closed sak96 closed 1 year ago

sak96 commented 1 year ago

Reproduce

" ~/.vim/vimrc
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter' " Git status bar
Plug 'vifm/vifm.vim' " add vifm support
call plug#end()
# run following commands
cd /tmp
mkdir temp && cd temp && git init
touch a.txt b.txt
vim a.txt # :Vifm
# select b.txt and  vifm errors out.

code which fails

The vifm will fail here.

    if a:exitcode != 0
        echoerr 'Got non-zero code from vifm: ' . a:exitcode
        call delete(a:listf)
        call delete(a:typef)
        return
    endif

The function call happens here.

        call s:HandleRunResults(v:shell_error, listf, typef, a:editcmd)
    endif

The Probable Cause

v:shell_error is not exit code of vifm but exit code of gitgutter shell cmd which runs thanks to autocmd.

Calling shell to execute: " vifm  /tmp/temp/temp  '--choose-files' '/tmp/v9q6zuF/8' '--on-choose' 'echo $VIFM_OPEN_TYPE >/tmp/v9q6zuF/9' '+command EditVim   :let $VIFM_OPEN_TYPE='\''edit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command VsplitVim :let $VIFM_OPEN_TYPE='\''vsplit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command SplitVim  :let $VIFM_OPEN_TYPE='\''split'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command DiffVim   :let $VIFM_OPEN_TYPE='\''vert diffsplit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command PeditVim  :let $VIFM_OPEN_TYPE='\''pedit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command TabVim    :let $VIFM_OPEN_TYPE='\''tablast | tab drop'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj'"
Executing ShellCmdPost Autocommands for "*"
autocommand call gitgutter#all(1)

Calling shell to execute: "(cd /tmp/temp/temp && git  ls-files -v --error-unmatch --full-name -z -- a.txt)>/tmp/v9q6zuF/10 2>&1"
Executing ShellCmdPost Autocommands for "*"
autocommand call s:sh_autocmd_handler()

autocommand call s:reset_untracked_cache(1)

autocommand call s:sh_autocmd_handler()

Executing ShellCmdPost Autocommands for "*"
autocommand call fugitive#DidChange(0)

Error detected while processing function <SNR>35_StartVifm[112]..<SNR>35_HandleRunResults:
line    2:
Got non-zero code from vifm: 1
xaizek commented 1 year ago

Thanks for a helpful report, should be fixed now.

sak96 commented 1 year ago

The fix was so simple ? i could have raised a pr. i was not able to follow the command completely so i just did not bother to think about the fix.

Calling shell to execute: " vifm  /tmp/temp/temp  '--choose-files' '/tmp/v9q6zuF/8' '--on-choose' 'echo $VIFM_OPEN_TYPE >/tmp/v9q6zuF/9' '+command EditVim   :let $VIFM_OPEN_TYPE='\''edit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command VsplitVim :let $VIFM_OPEN_TYPE='\''vsplit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command SplitVim  :let $VIFM_OPEN_TYPE='\''split'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command DiffVim   :let $VIFM_OPEN_TYPE='\''vert diffsplit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command PeditVim  :let $VIFM_OPEN_TYPE='\''pedit'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj' '+command TabVim    :let $VIFM_OPEN_TYPE='\''tablast | tab drop'\'' | execute '\''cnoremap j <cr>'\'' | normal gs:editj'"

Thanks for fixing it so quickly :grinning:

xaizek commented 1 year ago

I didn't actually know there is an auto-command for :! until now, just avoid triggering it.

However, gitgutter seems to be a problematic plugin as that auto-command can break many different things and should be updated to fix that.