sponsor Vim development Vim logo Vim Book Ad

diffchar.vim : Highlight the exact differences, based on characters and words

 script karma  Rating 54/17, Downloaded by 1542    Comments, bugs, improvements  Vim wiki

created by
Rick Howe
script type
This plugin has been developed in order to make diff mode more useful. Vim highlights all the text in between the first and last different characters on a changed line. But this plugin will find the exact differences between them, character by character - so called DiffChar.

For example, in diff mode: ( [DiffText], <DiffAdd> )

    (window A) The [quick brown fox jumps over the lazy] dog.
    (window B) The [lazy fox jumps over the quick brown] dog.

this plugin will exactly show the changed and added units:

    (window A) The [quick] <brown >fox jumps over the [lazy] dog.
    (window B) The [lazy] fox jumps over the [quick] <brown >dog.

For details and demo samples, please visit the following git repository:

Update : 6.0
* Defined a new TDChar command to toggle the highlights for specified range, and make it possible to select a block of lines in visual mode and toggle them by using <F8>.
* Changed the default value of g:DiffUnit from 'Char' to 'Word1', where \w\+ is handled as a single difference unit, to make more sense to usual case.
* Changed the default value of g:DiffSplitTime from 500 to 100 to switch more quickly and changed to check the time more often (unit-by-unit, not line-by-line) to detect the time limit earlier.
* Changed to use the g:DiffSplitTime, instead of the number of lines as an argument, in the DiffCharExpr() to switch to the diff command as accurately as specified.
* Improved the way to analyze the output of the diff command quickly.
* Enhanced to interactively update the highlights faster while editing when g:DiffUpdate is enabled.
* Changed the position of a pair cursor for a deleted unit on either its previous or next character instead of both.
* Fixed to ignore white spaces at line end when iwhite is specified in the 'diffopt' option.
* Fixed to enable to use a t:DiffModeSync tab page variable as well as its global one.
install details
Install https://github.com/rickhowe/diffchar.vim using your plugin manager. Or manually unzip and copy all folders in your ~/.vim or ~/vimfiles.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
diffchar6.0.zip 6.0 2016-01-30 7.0 Rick Howe Defined a new TDChar command, changed the default value of g:DiffUnit from 'Char' to 'Word1', and more enhancements and fixes.
diffchar.vim 5.5 2015-11-23 7.0 Rick Howe Introduced g:DiffModeSync to synchronously show/reset the highlights as the diff mode starts/ends. Changed to enable g:DiffUpdate as a default. Fixed several defects.
diffchar.vim 5.4 2015-10-06 7.0 Rick Howe Enhanced to show a position of a deleted unit with underline, and more.
diffchar.vim 5.3 2015-09-06 7.0 Rick Howe Performance improved for long lines and some defects fixed when the diff command is used for the diff tracing.
diffchar.vim 5.2 2015-08-15 7.0 Rick Howe Enhanced to provide a stable performance by splitting the diff tracing with this plugin's algorithm and the diff command.
diffchar.vim 5.1 2015-06-01 7.0 Rick Howe A workaround for patch 7.4.682, diff highlights can not be overwritten and will be left in all the lines.
diffchar.vim 5.0 2015-05-07 7.0 Rick Howe Improved to be 1.5 ~ 2.0 times faster. Introduced g:DiffMaxRatio to keep performance for long less-similar lines.
diffchar.vim 4.9 2015-02-18 7.0 Rick Howe Fixed DiffCharExpr() to keep the appropriate performance for large files.
diffchar.vim 4.81 2015-01-13 7.0 Rick Howe Enhanced to make DiffCharExpr() a bit faster by using uniq() or so.
diffchar.vim 4.8 2015-01-12 7.0 Rick Howe Enhanced to set the threshold for diffexpr option to switch internal/external to be faster on less differences and stable on many ones. Changed the way to select windows among more than 2 windows.
diffchar.vim 4.7 2014-12-26 7.0 Rick Howe Enhanced to use faster this plugin's diff algorithm and initially show exact differences on diff mode. Enhanced to make the key mappings configurable. Fixed to correctly adjust the iwhite unit position.
diffchar.vim.vim 4.6 2014-11-26 7.0 Rick Howe Fixed to correctly handle the color order and always highlight the first changed unit with DiffText in any color mode of g:DiffColors.
diffchar.vim 4.5 2014-11-08 7.0 Rick Howe Fixed to show the last "brown" on above example as added (not changed) units and to use your global variables defined in vimrc.
diffchar.vim 4.4 2014-07-21 7.0 Rick Howe Enhanced to follow diffopt's icase/iwhite options and to draw faster with a new function.
diffchar.vim 4.3 2014-07-03 7.0 Rick Howe Enhanced to differently show added/deleted/changed difference units with original diff highlightings.
diffchar.vim 4.2 2014-06-20 7.0 Rick Howe Enhanced to update the highlighted DiffChar units while editing.
diffchar.vim 4.1 2014-06-14 7.0 Rick Howe Implemented to echo a matching unit with its color when jumping cursor. And fixed a defect.
diffchar.vim 4.0 2014-06-11 7.0 Rick Howe Enhanced to easily find each difference unit pair on both windows.
diffchar.vim 3.6 2014-06-06 7.0 Rick Howe Added two difference unit types, "Word3" and "CSV(c)"
diffchar.vim 3.5 2014-06-01 7.0 Rick Howe Fixed defects: DiffChar highlighting units do not override/hide hlsearch.
diffchar.vim 3.4 2014-05-30 7.0 Rick Howe Enhanced to support individual DiffChar handling on each tab page.
diffchar.vim 3.3 2014-05-28 7.0 Rick Howe Enhanced to jump cursor to the DiffChar highlighting units.
diffchar.vim 3.2 2014-05-26 7.0 Rick Howe Enhanced to follow diff mode without any limitations.
diffchar.vim 3.1 2014-05-19 7.0 Rick Howe Enhanced for individual line by line highlightings and window layout handling.
diffchar.vim 3.0 2014-05-16 7.0 Rick Howe Implemented word by word differences.
diffchar.vim 2.1 2014-05-06 7.0 Rick Howe Coding changes in the O(NP) function for readability.
diffchar.vim 2.0 2014-05-05 7.0 Rick Howe Implemented the O(NP) and O(ND) Difference algorithms to improve the performance.
diffchar.vim 1.0 2014-05-02 7.0 Rick Howe Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo