Closed sjakobi closed 3 years ago
I did some digging, and apparently this is an issue with vim itself: https://github.com/vim/vim/issues/982. It occurs when the stdin passed to vim is not your TTY, but some file descriptor, e.g. a pipe.
vgrep
runs the editor by passing its own stdin
to the editor command. This works correctly for vim if you directly invoke vgrep
, but not if it is part of a pipe, which is exacty the case for the git vgrep
alias.
I can reproduce the issue with vim
, while it works correctly with neovim
and emacs
.
A possible solution is to replace the stdin in createProcess
in https://github.com/fmthoma/vgrep/blob/1a3761c04b1bcc0d5b40d4546470b5b5c6d74f47/app/Main.hs#L264 with a TTY (see https://hackage.haskell.org/package/process/docs/System-Process.html#v:createProcess), but this should be tested thoroughly with other editors.
@sjakobi Can you try with #50?
Thanks for looking into this, @fmthoma! I really enjoy using vgrep
.
@sjakobi Unfortunately, I cannot reproduce the problem with the file being always opened at the top.
What vgrep
basically does is call $EDITOR +n file
, where file
is the file to be opened and n
is the line number. Everything from there is handled by the editor. Could you try vim +5 <some file>
on your machine and check that the file is opened on line 5?
vim
seems to work alright. I should point out that the problem only comes up with git vgrep
. vgrep
on its own opens files on the right line.
I thought that the problem might be related to the non-standard shell I'm using, fish
, but it also happens in bash
.
Oh I think I've found a solution. Adding a -n
for line numbers to the git vgrep
alias does the trick:
vgrep = "!__git_vgrep () { git grep -n --color=always \"$@\" | vgrep; }; __git_vgrep"
When I use
git vgrep
with the alias defined in the README, I run into the above warning when I try to open a file. In addition, vim doesn't open the file on the line selected invgrep
, but on the first line, which is rather inconvenient.Is there a way to make
vim
play nice withgit vgrep
?