I use vimdiff to inspect differences between files, and some times it misses out a bit. for example, if I have the following two files:



int i = printf("hello\n") + 3;

showing them in vimdiff gives:

enter image description here

What I will want to see is that in b.c the h is not capitalized.

Is there a way to tell vimdiff to compare (in that line) just part of it (I mean, ignore the int i = and the + 3)?

  • 5
    The diffchar plugin is probably what you need but I have zero experience with it. Maybe someone with experience using it can give a good, detailed answer (or maybe an alternative).
    – tokoyami
    Commented Feb 6, 2015 at 11:30

1 Answer 1


I don't think this can be done by Vim itself. From :h view-diffs (emphasis mine):

hl-DiffText   DiffText        Changed text inside a Changed line.  Vim
                                finds the first character that is different,
                                and the last character that is different
                                (searching from the end of the line).  The
                                text in between is highlighted.  This means
                                that parts in the middle that are still the
                                same are highlighted anyway.  Only "iwhite" of
                                'diffopt' is used here.

Tokoyami's suggestion takes us one step closer. Install diffchar (Github link for those using a plugin autoloader). Since v4.7, with the plugin enabled, Vim automatically shows more exact differences:

enter image description here

  • You can press F7 (the default keymap) to toggle between the usual and the plugin. Reassign with:

    nmap <silent> <key> <Plug>ToggleDiffCharAllLines

    replacing <key> with an appropriate key code.

  • You can use more colors:

    let g:DiffColors=100
  • +1 but "one step closer" seems overly conservative to me. Diffchar totally solves this issue IMO.
    – Sparhawk
    Commented Jul 8, 2016 at 12:24
  • @Sparhawk well, it doesn't ignore the common elements in a line (OP wants just the changes highlighted)
    – muru
    Commented Jul 8, 2016 at 13:00
  • I'm not sure that I understand. Aren't the common elements ignored in this example (e.g. printf and ello)?
    – Sparhawk
    Commented Jul 8, 2016 at 22:10
  • 1
    @Sparhawk in this example, yes. But with more complex changes, it quickly becomes messy.
    – muru
    Commented Jul 9, 2016 at 7:44
  • Ah okay, so it's a bit buggy then… thanks for the information.
    – Sparhawk
    Commented Jul 9, 2016 at 10:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.