• Stars
    star
    357
  • Rank 119,149 (Top 3 %)
  • Language
    Vim Script
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Better Diff options for Vim

EnhancedDiff plugin Say Thanks!

A Vim plugin for creating better diffs (sometimes)

This plugin allows you to make use of the Patience diff algorithm for generating diffs to use with Vim. This needs the git command line tool available. (But see Update below)

You can also customize your setup to use any other tool to generated diffs (e.g. mercurial) Read the help on how to configure the plugin accordingly.

Here are some screenshots that visualize how the patience/histogram algorithm work.

This is the default diff generated by Vim: Default diff

Now change that to using the "histogram" algorithm by running :EnhancedDiff histogram If Vim is in diff mode, the diff will be updated to this:

histogram diff

Note, that the Patience algorithm might not always provide better diffs. But using this plugin you can at least easily switch between different diffs.

Update

Starting with Vim 8.1.0360 Vim now comes bundled with the xdiff library and is able to handle diff internally without falling back to calling diff as external tool.

This means, one can now simply set diffopt:

if has("patch-8.1.0360")
    set diffopt+=internal,algorithm:patience
endif

and Vim will use the patience diff algorithm when creating a diff.

In addition, Vim can now parse context diffs (currently with only zero context lines) from a diff tool when using diff as external tool. So a translation to an ed-like diff is not needed anymore.

So in essence, starting with that Vim version, you don't need to use this plugin anymore.

Ignoring parts of a file

Using the command :EnhancedDiffIgnorePat pat you can define patterns, that will be ignored before feeding the buffer contents to the diff program. Internally this will be handled by substituting those matches with 'XX' so that the content will look like the same for the diff binary.

This is how it looks like with a pattern of ^[^;]\+; and ;[^;]\+$ diff_ignore

Installation

Use the plugin manager of your choice:

  • Pathogen
    • git clone https://github.com/chrisbra/vim-diff-enhanced.git ~/.vim/bundle/vim-enhanced-diff
    • :Helptags (only needed once after the installation to install the documentation)
  • NeoBundle
    • NeoBundle 'chrisbra/vim-diff-enhanced'
  • Vundle
    • Plugin 'chrisbra/vim-diff-enhanced'
  • Vim-Plug
    • Plug 'chrisbra/vim-diff-enhanced'

Alternatively download the stable version of the plugin, edit it with Vim (vim EnhancedDiff-XXX.vmb) and simply source it (:so %). Restart and take a look at the help (:h EnhancedDiff.txt)

Usage

Once installed, take a look at the help at :h EnhancedDiff

Here is a short overview of the functionality provided by the plugin:

Ex commands:

:PatienceDiff - Use the Patience Diff algorithm for the next diff mode

:EnhancedDiff <algorithm> - Use <algorithm> to generate the diff. Use any of

  • myers Default Diff algorithm used
  • default Alias for myers algorithm
  • histogram Fast version of patience algorithm
  • minimal Default diff algorithm, trying harder to minimize the diff
  • patience Patience diff algorithm.

Note: Those 2 commands use the git command line tool internally to generate the diffs. Make sure you have at least git version 1.8.2 installed.

:EnhancedDiffDisable - Disable plugin (and use default Vim diff capabilities).

FAQ

How can I enable the patience diff algorithm when starting as vimdiff / git difftool / ... ?

In that case, add this snippet to your .vimrc:

" started In Diff-Mode set diffexpr (plugin not loaded yet)
if &diff
    let &diffexpr='EnhancedDiff#Diff("git diff", "--diff-algorithm=patience")'
endif

License & Copyright

ยฉ 2015 by Christian Brabandt. The Vim License applies. See :h license

NO WARRANTY, EXPRESS OR IMPLIED. USE AT-YOUR-OWN-RISK

More Repositories

1

csv.vim

A Filetype plugin for csv files
Vim Script
1,266
star
2

NrrwRgn

A Narrow Region Plugin for vim (like Emacs Narrow Region)
Vim Script
673
star
3

Colorizer

color hex codes and color names
Vim Script
544
star
4

unicode.vim

A Vim plugin that provides a completion function for Unicode glyphs
Vim Script
451
star
5

Recover.vim

A Plugin to show a diff, whenever recovering a buffer
Vim Script
246
star
6

vim_faq

The Vim FAQ from http://vimdoc.sourceforge.net/ (outdated), updates available at:
HTML
144
star
7

changesPlugin

A Vim Plugin for indicating changes as colored bars using signs.
Vim Script
106
star
8

SudoEdit.vim

Edit Files using sudo or su or any other tool
Vim Script
64
star
9

matchit

The matchit plugin from Vim
Vim Script
61
star
10

vim-zsh

Official Vim Runtime Files for Zsh
Vim Script
41
star
11

improvedft

An improved ft command for Vim
Vim Script
39
star
12

vim-autosave

autosave your work
Vim Script
38
star
13

histwin.vim

A Vim Plugin for browsing the undo tree
Visual Basic
38
star
14

vim-autoread

Use tail -f on a buffer and append new content
Vim Script
36
star
15

wikipedia2text

A commandline tool for querying the Wikipedia
Shell
32
star
16

Replay

A plugin for vim that enables you to replay your editing Session
Vim Script
32
star
17

DynamicSigns

Using Signs for displaying various things
Vim Script
31
star
18

CheckAttach

Check for attachments when writing mails with mutt
Vim Script
28
star
19

vpager

Pipe input from Vims terminal directly back into Vim
Shell
25
star
20

vim-mq-patches

private MQ Patches for Vim
C
23
star
21

vim_dotfiles

my personal vim config
Vim Script
18
star
22

DistractFree

DistractFree
Vim Script
17
star
23

vim-sh-indent

Vim Shell Indent Repository
Shell
15
star
24

vim-show-char

Vim Plugin for displaying whitespace
Vim Script
14
star
25

vim-xml-runtime

Vim filetype plugin for XML files
Vim Script
11
star
26

BufTimer

Time your editing duration
Vim Script
10
star
27

youtube2audio

A downloader that converts youtube videos into music using mplayer and clive/youtube-dl
Shell
6
star
28

mutt

official Mutt Mirror from gitlab https://gitlab.com/muttmua/mutt/
C
6
star
29

vim-commentary

Comment some stuff
Vim Script
4
star
30

vim-appimage

Appimage builds for GVim
Shell
4
star
31

vim-history

C
4
star
32

BackgroundColor.vim

A Simple Plugin for Defining A Background Color for your Vim using Signs
Vim Script
4
star
33

SaveSigns.vim

A Vim Plugin to Save and Restore your Signs
Vim Script
4
star
34

vim-sqloracle-syntax

Oracle SQL Syntax files for Vim
Vim Script
3
star
35

Join

Improved algorithm for joining large files
Vim Script
3
star
36

chrisbra

3
star
37

vim-rc-syntax

Vim RC Syntax files
Vim Script
2
star
38

zugferd

a sample repository on how to create ZUGFeRD pdf files
XSLT
2
star
39

vim-kconfig

kconfig runtime files for Vim
Vim Script
2
star
40

chrisbra.github.com

Personal Webpage
2
star
41

vim-misc

miscellaneous Vim functions
Vim Script
2
star
42

ftpbackup

A simple backup for your ftp-share
Perl
2
star
43

Calendar_CSV_DACH

Create a Calendar in CSV format for Germany, Austria, Switzerland
Perl
2
star
44

xmlformat

A Vim plugin for formatting XML files
Vim Script
2
star
45

vim-PowerCenter-syntax

syntax file for Informatica PowerCenter Logfiles
Vim Script
1
star
46

vim-ci

1
star
47

vim-tex-indent

official Vim indent file for tex
Vim Script
1
star
48

git-omni-deployment

A tool for a slightly better deployment experience when using IBIs Omni-Gen
Shell
1
star
49

vimcrypt

Encode/Decode Vims Sodium encryption
C
1
star
50

Terraform_Test

HCL
1
star
51

vim-screencasts

Some Screencasts
1
star
52

CleverPut

pasting easily (and adjust Whitespace)
Vim Script
1
star
53

ci_configuration

testing some boring ci config stuff. Nothing to see here.
1
star
54

ism_ci

Make iSM/iIT demo for CI
Shell
1
star
55

putty

PuTTY SSH and Telnet client with TrueColor patch
C
1
star
56

vim-search_escape

Convert regexp patterns
Vim Script
1
star