【问题标题】:How do I use vim as 'git show' editor?如何使用 vim 作为“git show”编辑器?
【发布时间】:2015-01-20 14:49:34
【问题描述】:

How do I use vim as 'git log' editor? 中描述的所有内容都不适用于 git show 。 我经常使用

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

更新我找到了解决方案:

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

更好 (2021-02-05)

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

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

【问题讨论】:

    标签: git vim


    【解决方案1】:

    您可以使用以下命令:

    PAGER='vim -' git -c color.ui=false show
    

    【讨论】:

    • 我猜他选择了他自己帖子的更新作为接受的答案
    【解决方案2】:

    这是解决该问题的 Twitter 帖子。

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

    git showvim 和语法高亮一起使用:vimgitshow() { git show "$1" | vim - "+set filetype=${1##*.}"; }

    【讨论】:

    • 这也是一个类似于别名的bash函数,不能解决原来的问题,只是解决它。
    • @Sérgio 您将其放入~/.bashrc 以便在您打开新终端时定义它。那么你可以使用vimgitshow 而不是git show
    • +set filetype?${1##*.}";} 到底是做什么的?
    • (修正错字)我把那段代码放在哪里?谢谢 lucidbrot
    【解决方案3】:

    这对我有用:

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

    疯狂的 vim 参数在这里找到:https://stackoverflow.com/a/17015531/610634

    【讨论】:

    • 我看到Error detected while processing command line: E486: Pattern not found: \e.\{-}m
    • 您可以使用/e 标志禁止此类警告。
    【解决方案4】:

    您可能还想使用比补丁语法高亮更好的差异。它允许您使用git show 并查看vimdiff 中每个文件的差异。看到这个answer

    【讨论】:

      【解决方案5】:

      可以在编辑模式中简单地使用git show bf9f84042 | vim -,或者在只读模式中使用git show bf9f84042 | vim -R -,无需更改gitconfig

      git config --global diff.tool vimdiff 使用 vimdiff 作为 diff.tool,然后 git difftool bf9f042 232wf2f 进行 diff

      【讨论】:

        猜你喜欢
        • 2013-05-15
        • 2011-01-10
        • 2019-01-30
        • 1970-01-01
        • 2011-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多