2

I use vim and git primarily for editing prose documents in LaTeX or Markdown, not for coding. For this reason, my go-to git diff command is git wdiff, where the relevant part of .gitconfig reads

    wdiff = "diff --color-words='[^][<>()\\{},.;:?/|\\\\=+*&^%$#@!~`\"'\\''[:space:]]+|[][<>(){},.;:?/|\\\\=+*&^%$#@!~`\"'\\'']' --histogram"

(I got the regex from here.)

But right now when I use vim-fugitive to run :Git wdiff, I get garbled output with some sort ASCII encoding for the colors instead of the actual colors themselves, for example:

^[[1mdiff --git a/interview.md b/interview.md^[[m
^[[1mindex a464fb2..fb379fc 100644^[[m
^[[1m--- a/interview.md^[[m
^[[1m+++ b/interview.md^[[m
^[[36m@@ -129,4 +129,4 @@^[[m ^[[mand instituted several different online^[[m
seminars. ^[[m

Some prose ^[[32mwith some more verbiage inserted^[[m that ends here.

The :Git diff command works fine and outputs colored diff output as expected.

How can I get fugitive to output diff --color-words properly? (Or better yet, how can I get it to do so with the customized regex printed above?)

7
  • fugitive don't recognize ascii color codes (nor should it, a/c unix philosohpy). You should look for questions like this instead. I myself would simply not use the color codes and let fugitive decide the colors based on the + and - signs. Is there any particular reason you disabled the signs? And is enabling them (with a new alias that don't use color codes) for vim-fugitive out of the question? Cause if not, then the solution is pretty simple.
    – 3N4N
    Aug 15, 2022 at 18:15
  • Oh, right. You don't want noise (of the symbols). Yeah then you should definitely use a plugin for handling ascii color codes.
    – 3N4N
    Aug 15, 2022 at 18:18
  • I'd just use :term git wdiff % (or make a custom command if it's a regular/common use-case).
    – 3N4N
    Aug 15, 2022 at 18:29
  • I'd rather not use :term commands if possible. Aug 15, 2022 at 19:41
  • That is, I'm hoping for a solution that will use vim-fugitive in just the same way as :Git diff, with the only difference being the --color-words formatting of the output (which, as you say, indicates changes not linewise with + and - but rather word-wise with nothing but the color coding to distinguish deletions and additions from text that is unchanged). Aug 15, 2022 at 20:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.