如何用vim作为传呼机来设置彩色的git diff [英] How to setup coloured git diff with vim as a pager

查看:255
本文介绍了如何用vim作为传呼机来设置彩色的git diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b


  1. 使用vim作为差异寻呼机

  2. 在交互式模式下添加文件时保留diff的颜色

我的〜/ .gitconfig setup:

  [color] 
ui = auto
#diff = false

[pager]
diff = vim -

/i.stack.imgur.com/uVYrv.pngalt =交互式添加>



这个缺点是vim中的diff被破坏。查看 git diff 的输出:



当使用 git diff | vim - 颜色是确定的,但我懒得输入完整的命令。是否有任何已知的方法可以在两种情况下都保留颜色? 解决方案

您需要安装 AnsiEsc插件,并在加载文件后运行:AnsiEsc 。你可以将pager设置为 vim -c AnsiEsc - 来做到这一点。

另外,使用vim自己的高亮显示:using同样的方法( -c命令)运行

 %sm / \\ \\ e.\ { - } m // g 
set ft = diff

  diff =vim -c'%sm / \\e.\\ { - } m // g'-c'set ft = diff' - 


I am unable to configure git to follow my requests:

  1. use vim as a diff pager
  2. keep colours for diff when adding files in interactive mode

My ~/.gitconfig setup:

[color]
    ui = auto
    # diff = false

[pager]
    diff = vim -

With this configuration the interactive mode for git add --interactive produces coloured output as expected:

The downside of this is that diff in vim is corrupted. See the output of git diff:

When using git diff | vim - the colours are OK but I'm too lazy to type the full command. Is there any known method that preserves colours in both cases?

解决方案

You need to install AnsiEsc plugin and run :AnsiEsc just after loading file. You can set pager to vim -c AnsiEsc - to do this.

Alternatively, use vim own highlighting: using the same method (-c command) run

%sm/\e.\{-}m//g
set ft=diff

:

    diff = "vim -c '%sm/\\e.\\{-}m//g' -c 'set ft=diff' -"

这篇关于如何用vim作为传呼机来设置彩色的git diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆