Questions tagged [word-diff]

Comparison between two or more words.

Compare words by distance (as in ), by different letters or by checking if two words are equals.

35 questions
147
votes
17 answers

Highlight the difference between two strings in PHP

What is the easiest way to highlight the difference between two strings in PHP? I'm thinking along the lines of the Stack Overflow edit history page, where new text is in green and removed text is in red. If there are any pre-written functions or…
Philip Morton
  • 129,733
  • 38
  • 88
  • 97
118
votes
13 answers

Highlight changed lines and changed bytes in each changed line

Open Source project Trac has an excellent diff highlighter — it highlights changed lines and changed bytes in each changed line! See here or here for examples. Is there way to use the same color highlight (i.e. changed lines and changed bytes too)…
user256497
76
votes
5 answers

How can I use `git diff --color-words` outside a Git repository?

How can I get output like in git diff --color-words, but outside Git? Closest thing is wdiff -t, but it underlines/inverts things instead of using green/red colours and does not allow specifying my whitespace regex.
Vi.
  • 37,014
  • 18
  • 93
  • 148
32
votes
12 answers

How can I optimize this Python code to generate all words with word-distance 1?

Profiling shows this is the slowest segment of my code for a little word game I wrote: def distance(word1, word2): difference = 0 for i in range(len(word1)): if word1[i] != word2[i]: difference += 1 return…
Davy8
  • 30,868
  • 25
  • 115
  • 173
30
votes
2 answers

Is it possible to make --word-diff default in git diff, git gui, gitk

Is it possible to set an option that git diff is always using --word-diff=color whenever displaying diffs? I know that there are command line arguments for gitk, git-gui and git diff, but are there config options I can set globally? I found that…
Andreas Mueller
  • 27,470
  • 8
  • 62
  • 74
26
votes
1 answer

How to find difference between two strings?

I have two strings and would like to display the difference between them. For example, if I have the strings "I am from Mars" and "I am from Venus", the output could be "I am from Venus". (Typically used to show what changed in an audit log,…
WanKenoobi
25
votes
12 answers

Diff Tool That Ignores Newlines

I frequently need to compare SQL procedures to determine what has changed in the newest version. The problem is, everyone has their own style of formatting, and SQL doesn't (usually) care about where one puts their newlines (e.g. where clauses all…
Prometheus
  • 870
  • 1
  • 8
  • 14
24
votes
6 answers

showing differences within a line in diff output

This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know of a tool which can show the same (ex, via color) on the command line? Another way to think of this is wanting to diff each difference in a…
Brian Harris
  • 2,735
  • 3
  • 22
  • 34
23
votes
1 answer

Possible to enable the word-diff option in github to see more granular changes to a line?

I'm exploring usage of github for text versioning. A major problem with github is the fact that changes are by line. So if you make a word or phrase change that is rather granular, the whole line appears to have been changed. In git itself, there's…
fraxture
  • 5,113
  • 4
  • 43
  • 83
19
votes
4 answers

How to display word differences using c#?

I would like to show the differences between two blocks of text. Rather than comparing lines of text or individual characters, I would like to just compare words separated by specified characters ('\n', ' ', '\t' for example). My main reasoning…
Jim Geurts
  • 20,189
  • 23
  • 95
  • 116
16
votes
2 answers

newline-ignoring diff / diff across multiple lines / reflow-ignoring diff

Does anybody know of a diff-like tool that can show me the changes between two text files, but ignore changes in whitespace including newlines? Here's an example: the quick brown fox jumped over the lazy bear. the quick brown fox jumped over the…
Adam
  • 1,409
  • 12
  • 19
14
votes
1 answer

command line recursive word-based diff?

is there a command line program that gives recursive word-based diff (on 2 directories)? diff -u is recursive, but it doesn't do word by word comparison. wdiff and dwdiff does word based diff but there are not built-in options for recursive diff. I…
ceiling cat
  • 5,501
  • 9
  • 38
  • 51
10
votes
3 answers

Is there a way to diff files sentence-by-sentence instead of line-by-line?

Just trying to get diff to work better for certain kinds of documents. With LaTeX, for example, I might have a long paragraph that is strictly just one line, but I don't want to see that entire paragraph if just a sentence is changed. Particularly…
Chris
  • 1,632
  • 2
  • 16
  • 22
10
votes
1 answer

use git's word-diff for latex files

I would like to have git diff outputs me regular diffs for all files, except *.tex. For *.tex files, I would like to see the output of git diff --word-diff. I was playing around with .gitattributes and .gitconfig, but the furthest I got was to get a…
Nikola Knezevic
  • 789
  • 5
  • 20
10
votes
1 answer

How to git-apply a git word diff

I needed to edit a messy commit commit that only changed a word in a few subsequent rows, keeping some of those changes and removing others. The changes were easy to see in git diff --word-diff, and in that format I could easily edit the hunks to do…
Anaphory
  • 6,045
  • 4
  • 37
  • 68
1
2 3