git-jump is an amazing little script that can be used to start Vim with the quickfix list populated with interesting things:
- The beginning of any diff hunks.
- The beginning of any merge conflict markers.
- Any grep matches, including the column of the first match on a line.
- Any whitespace errors detected by
git diff --check
.
Example usage:
$ git jump diff
$ git jump grep GetUser
But the original script can't be used to populate the quickfix list from within Vim. Bummer…
This hack makes it possible to call git-jump
in a way that forces it to use cat
when $GIT_EDITOR
is not set.
Example:
:cexpr system('git jump diff')
Doesn't work because git-jump tries and fails to use Vim
:cexpr system('GIT_EDITOR= git jump diff')
Works because $GIT_EDITOR is empty so the script defaults to cat
Having the same feature inside and outside of Vim is quite handy but that's a lot to type! Let's turn that into a proper command:
:command! -bar -nargs=* Jump cexpr system('GIT_EDITOR= git jump ' . expand(<q-args>))
that we can use easily:
:Jump diff
:Jump merge
Rather than clearing
GIT_EDITOR
when invoking from Vim you could test if stdout is to a terminal or not, e.g.This allows for
git jump
to be used transparently in and outside of Vim.