14

all as described in How do I use vim as 'git log' editor? doesn't work for git show . I use often

git show HEAD

ctrl+z 

ps 

  PID TTY          TIME CMD
 7083 pts/8    00:00:06 bash
31758 pts/8    00:00:00 git
31759 pts/8    00:00:00 less
31762 pts/8    00:00:00 ps

Update I found the solution :

git config --global pager.color false
git config --global pager.show 'vim -R -'

Even better (2021-02-05)

git config --global core.pager 'vim -R -'

https://stackoverflow.com/a/16666055/778517

Sérgio
  • 6,966
  • 1
  • 48
  • 53

5 Answers5

13

You can use the following command:

PAGER='vim -' git -c color.ui=false show
manzur
  • 682
  • 3
  • 7
4

Here is a Twitter post to solve that problem.

https://twitter.com/oliviergay/status/179692941063888896

Using git show with vim and syntax highlighting: vimgitshow() { git show "$1" | vim - "+set filetype=${1##*.}"; }

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
René Höhle
  • 26,716
  • 22
  • 73
  • 82
2

This worked for me:

git config --global pager.show "vim -c '%sm/\\e.\\{-}m//g' -c 'set ft=diff' +1 -"

Crazy vim args found here: https://stackoverflow.com/a/17015531/610634

Community
  • 1
  • 1
Coeffect
  • 8,772
  • 2
  • 27
  • 42
0

You might also want to use a better diff than just patch syntax highlighting. It allows you to use git show and see the diff for each file in vimdiff. See this answer.

Community
  • 1
  • 1
Yuri Pozniak
  • 667
  • 7
  • 11
0

can simply use git show bf9f84042 | vim - in edit mod, or git show bf9f84042 | vim -R - in read only mod, without changing gitconfig

or

git config --global diff.tool vimdiff using vimdiff as diff.tool, and then git difftool bf9f042 232wf2f to diff

OverSang
  • 11
  • 2