Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to diff rewrapped text?

Tags:

diff

word-wrap

When editing documents I always stick to a certain line width of max 80 or 150 characters, depends what I am writing (code, text, etc.). If I change only a little the whole paragraph will shift and hence multiple lines are now in different order to optimal fit for the given line width. How do I diff this to see the actual real change an not the rewrapping artifacts?

Example, textwidth=30: enter image description here

The actual changes are rather tiny:

  • line 9 insert: "Now I change a little"
  • line 15 insert: "Fill in here something and write totally new stuff with much more lines. "
  • line 18 change: s/Duis/TYPO/

The fact that I use (g)vimdiff here is of no matter, if other software can accomplish the desired diff.

Of course software is designed to wrap automatically when text reaches window borders, so I also tried to use just line breaks in the end of a paragraph. The reason why this is not good is, that automatically diffs are line based, and for small changes in paragraphs I get the whole line, meaning then the whole paragraph as diff update :(.

like image 690
math Avatar asked Jan 12 '12 07:01

math


3 Answers

GNU wdiff does a word-by-word diff, not treating spaces and new lines any differently. One can even find vim syntax files for it (e.g. here).

$ cat file1
Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Aenean vel molestie
nulla. Pellentesque placerat lacus vel
eros malesuada tristique. Nulla vitae
volutpat justo. Donec est mauris,

$ cat file2
Lorem amet, consectetur adipiscing some
inserted text! elit. Aenean vel molestie
nulla. Pellentesque placerat lacus vel
eros malesuada replacement. Nulla vitae
volutpat justo. Donec est mauris,

$ wdiff file1 file2
Lorem [-ipsum dolor sit-] amet, consectetur
adipiscing {+some inserted text!+} elit. Aenean vel molestie
nulla. Pellentesque placerat lacus vel
eros malesuada [-tristique.-] {+replacement.+} Nulla vitae
volutpat justo. Donec est mauris

([- ... -] is deleted text, {+ ... +} is inserted text).

(There are other diff programs that do a similar thing: e.g. adiff, and maybe some of the ones listed in https://stackoverflow.com/questions/12625/best-diff-tool)

like image 173
huon Avatar answered Nov 15 '22 10:11

huon


I like Beyond Compare for this kind of side-by-side file comparison. Also lets you do folder comparisons and bit-level comparisons, and you can right-click to select the left-hand file to compare, then another to select the right-hand one; or select two files and right-click Compare to bring them both up straight away.

enter image description here

like image 33
Darth Continent Avatar answered Nov 15 '22 10:11

Darth Continent


I use DiffMerge which is free and available on many platforms.

enter image description here

like image 32
Gery Avatar answered Nov 15 '22 10:11

Gery