9

Is there a stable tool (option/plugin of an existing tool: vimdiff, diff, etc) in Linux to do diff between two text files characterwise?

I would like to see the longest common subsequence between my two files highlighted. There is a classic polynomial-time algorithm for that, but the standard tools seem to only work line by line.

2

Good old cmp does a characterwise diff. It's been a part of UNIX for about 40 years. https://www.freebsd.org/cgi/man.cgi?query=cmp&apropos=0&sektion=0&manpath=Unix+Seventh+Edition&arch=default&format=html

Unfortunately, it stops at the first differing character, so I don't know if this answer is useful for you.

  • Thanks. I just ran a cmp -bl ... after finding this answer and it reported multiple differences and their positions. My version is cmp (GNU diffutils) 3.6. – Dzamo Norton Dec 3 '18 at 17:49
2

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
    

Unfortunately, this doesn't work across lines, best I can tell. However, common regions are left un-highlighted (and folded, if they grow too long), so you might be able to take advantage of that.


Copied from my Vi and Vim Stack Exchange post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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