Git Jump to Vim Quickfix

git ships with a script called git-jump to populate vim's quickfix list with hunks or merge conflicts… without using any vim plugins at all.

My friend Seth and I were talking about the quickfix list. My first introduction to the quickfix was back in school, working with compilers. It was my best friend then… make some changes, check the quick fix, clean it out, continue… it's the best!

Because I haven't been working with compiled languages in a long while I've been using quickfix for other things. For years, it's been my solution to the "search and replace in project" problem:

  1. Use :grep to populate the quickfix list with the locations of everything I want to change.
  2. Record a macro that replaces this instance with the new one, and navigates to the next location (:cn) and calls itself.
  3. Profit!

Thanks to how awesome :netrw is, that even works over FTP or SSH.

While thinking of good reasons to use quickfix over the buffer list, I realized a couple of other neat tricks using some modern neovim tooling:

Telescope

I use telescope.nvim pretty much everywhere now. By default, if you press <c-q> in a telescope view, it dumps the selection or marks into your quickfix. I'm using this with live grep often to do some spelunking on a particular variable.

GitSigns

Like gitgutter before it, gitsigns has commands for dumping current hunks or conflict markers into quickfix. While I was researching this, I found yet another cool tool!

git jump

While research the git workflow (because we all spend time in merge conflicts!) I came across a script that ships with git-contrib: git-jump

git-jump will work on any computer or server with vim and git (so, nearly all!?) There have been a few times working on a server or container that I really could have used this, so I'm excited to have this for the next time I'm working on a remote server or someone else's workstation.

Chris Dillon kindly pointed out a robust alias for git-jump so that you can use it as git jump in your .gitconfig:

[alias]
  "jump = "!$(brew --prefix git)/share/git-core/contrib/git-jump/git-jump""

Changelog
  • 2022-06-08 11:31:29 -0500
    Rename articles

  • 2022-06-07 15:27:31 -0500
    Adding Admonitions

  • 2022-04-15 13:04:51 -0500
    Adjust the git alias thanks to Chris Dillon

    From Chris:

    > About the git jump post, there's a version and also install agnostic way to get the installed path. Homebrew is changing from /usr/local and the version of git might change so that alias will break. Homebrew will link the whole directory so you can just go to the homebrew root and navigate to git.
    >
    > So this alias will work:
    > `jump = "!$(brew --prefix git)/share/git-core/contrib/git-jump/git-jump"` which survives version changes but also the upcoming move to `/opt/homebrew` for Apple Silicon.

    Thank you sir!

  • 2022-04-14 16:25:11 -0500
    Fix link on gitsigns

  • 2022-04-14 16:22:50 -0500
    Vim Quickfix