3

Git Jump to Vim Quickfix

 2 years ago
source link: https://evantravers.com/articles/2022/04/14/git-jump-to-vim-quickfix/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Git Jump to Vim Quickfix

April 14, 2022

tl;dr: 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.

There’s probably a more robust way to do this, but you can also alias git-jump so that you can use it as git jump in your .gitconfig:

[alias]
  jump = !/usr/local/Cellar/git/2.35.2/share/git-core/contrib/git-jump/git-jump

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK