How do I use vim as 'git log' editor?
Asked Answered
C

4

12

When I run git log, what exactly is the editor git log is using?

Also:

  1. Is there anyway I can use vim as my default editor for git log?
  2. If I want to search against the git log, what's the best way? Now I'm doing something like: git log | grep bla.
Cognate answered 21/5, 2013 at 9:2 Comment(3)
The output of $ git log is not something you edit so why exactly do you want to use an editor to view it?Mallet
@Mallet mainly just try to search it. Since the guys pointed out, less has a subset of vim search functionality, I guess I can live with less now.Cognate
less has /, ?, n and N, it supports regex search. $ man less is a very interesting read.Mallet
H
31

The git log command pipes it's output by default into a pager, not an editor. This pager is usually less or more on most systems. You can change the default pager to vim with the command:

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

Now you can search using vim functionality with / as usual.

Hydroxide answered 21/5, 2013 at 9:4 Comment(5)
less obeys a subset of vim search functionalityDeweese
@honk 'vim - ', what does '-' there do?Cognate
@Shengjie: It makes vim read from STDIN. Usually a good idea to add -R for read-only mode it that case as well.Cafard
@Shengjie: for many utilities, - as file name means stdin or stdout depending on contextRouse
git config --global core.pager 'vim -R -' , -R is important to quit quicklySoughtafter
P
1

You may want to look at viewlog.

It gives you a terminal gui interface to all commits. It will also open the file in the editor of your choice. You can search for relevant commits using the --grep flag.

Principality answered 26/1, 2016 at 20:13 Comment(0)
I
1

This worked for me: git log | vim -R -

Instill answered 4/7, 2021 at 4:30 Comment(2)
Hey, what's point of hypen behind '-R'? (I found without '-' behind '-R', it works as well)Niemeyer
@Niemeyer this indicates "Readonly mode (like "view")Quadrille
W
0

I had write a bash script to switch from using vim as editor to diff-so-fancy.

VT() {
    gitlogflag=true
    if [ -e "$HOME/.myscriptvar" ] ; then
        gitlogflag=$(cat "$HOME/.myscriptvar")
    fi
    if [ "$gitlogflag" = true ]; then
        git config --global pager.show "vim -c '%sm/\\e.\\{-}m//g' -c 'setlocal buftype=nofile' -c 'set ft=diff' +3 -";
        gitlogflag=false
    else
        git config --global pager.show "diff-so-fancy | less --tabs=1,5 -RFX";
        gitlogflag=true
    fi
    echo "$gitlogflag" > $HOME/.myscriptvar
}

I recommend you to use diff-so-fancy.

If you just want to use vim as your git log editor git config --global pager.show "vim -c '%sm/\\e.\\{-}m//g' -c will satisfy you.

Waterfowl answered 18/8, 2016 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.