Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active March 19, 2023 07:26
Show Gist options
  • Save romainl/5b827f4aafa7ee29bdc70282ecc31640 to your computer and use it in GitHub Desktop.
Save romainl/5b827f4aafa7ee29bdc70282ecc31640 to your computer and use it in GitHub Desktop.
Super cheap git blame

Super cheap git blame

git blame current line

:GB

git blame range

:7,13GB
:,+5GB
:?foo?,$GB
:'<,'>GB

git blame full buffer

:%GB

My Vim-related gists.

command! -range GB echo join(systemlist("git -C " . shellescape(expand('%:p:h')) . " blame -L <line1>,<line2> " . expand('%:t')), "\n")
@romainl
Copy link
Author

romainl commented Apr 16, 2019

IDEA: make it possible to pass an optional argument:

:GB HEAD~6

@kkoomen
Copy link

kkoomen commented Aug 3, 2019

When using commands involving git I suggest to always use the -C <path> flag. Assuming I am in my home directory and I open ~/projects/<name>/some/path/to/file then this command will not work, because I'm running Vim outside of the Git repository.

I suggest to use this command:

command! -range GB echo join(systemlist("git -C " . shellescape(expand('%:p:h')) . " blame -L <line1>,<line2> " . expand('%')), "\n")

@romainl
Copy link
Author

romainl commented Aug 3, 2019

@kkoomen, that's a nice improvement, thanks.

@Konfekt
Copy link

Konfekt commented Oct 25, 2019

If -C " . shellescape(expand('%:p:h')) is used, then correspondingly also expand('%:t') instead of '%'.

@romainl
Copy link
Author

romainl commented Dec 14, 2019

@Konfect, fixed, thanks.

@axvr
Copy link

axvr commented Dec 26, 2019

IDEA: make it possible to pass an optional argument:

:GB HEAD~6

This has been working well for me.

command! -nargs=? -range GB echo join(systemlist("git -C " . shellescape(expand('%:p:h')) . " blame -L <line1>,<line2> <args> -- " . expand('%:t')), "\n")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment