Giter Site home page Giter Site logo

vim-diff-enhanced's Introduction

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

vim-diff-enhanced's People

Contributors

bryant1410 avatar chrisbra avatar gbarta-atex avatar hcgraf avatar idbrii avatar roy-orbison avatar xuyangy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-diff-enhanced's Issues

Maybe include a sample file... not sure if working

I tried this and tried a few "CustomDiff" algorithms and then did a "diffu", but didn't see
any changes in my diff window. It's possible it had something to do with my file choices, but
dunno. Also just noticed, I have "-w" set in my .vimrc file:
~/.vimrc:
let &diffopt+="-w"

I compared two ".h" files:
samplexity.h & samplexity.h.orig

Thanks!

(Attached)

samplexity.h.txt
samplexity.h.orig.txt

no inline diffs are shown

Is there anything that needs to be configured in order to get inline differences highlighted instead of the whole line?

I've tried with 'patience' and 'histogram' without success. My sample buffers are
first buffer:

test

second buffer:

this test;

The only caveat is that these buffers are not saved to any file... Would that make a difference?

Setting patience diff as the default

Hi Chistian,

I know this is going to sound like a stupid question, but I can't figure it out. How do I apply :PatienceDiff on vim startup (so that when I run vimdiff, all my files get diffed with the patience algorithm)?

Putting PatienceDiff in my .vimrc yields:

line  449:
E492: Not an editor command: PatienceDiff

While if I execute it after the file I loaded by typing :PatienceDiff, everything works fine.

EDIT: I have made sure to put the PatienceDiff invocation after loading the vim-diff-enhanced plugin with Vundle.

EnhancedDiffIgnorePat specify replacement string

Hi,

please make EnhancedDiffIgnorePat take an additional argument to specify the replacement string to be used instead. I'd like to embed parts of the data, so simply using the optional argument in the replace call would be enough - it could then contain backreferences into the matched string like \1.

Thank you!

CustomDiff fails on with Windows gvim and cygwin git

CustomDiff fails on Win7 with gvim from vim.org (7.4.0) and cygwin git (2.1.1).

:CustomDiff histogram
EnhancedDiff: git diff Error executing "git diff --diff-algorithm=histogram -U0 C:/Users/davidb/AppData/Local/Temp/VIoEC75.tmp C:/Users/davidb/AppData/Local/Temp/VInEC76.tmp"
EnhancedDiff: fatal: Invalid object name 'C'.

(I get a similar failure with or without set shellslash. I haven't figured out changing 'shell' to bash, but that might fix it.)

Looks like since the v:fname_in/out path names assume git will understand the same kinds of paths as gvim, but cygwin doesn't understand drive letters it all falls down. I'm not sure if there's something you want to fix (I should probably use msysgit, but it's too far removed from shell-useful).

I can work around it by making the paths relative (in ~/.vim/after/plugin/enhanceddiff.vim) with :cd $TEMP:

if has('win32')
    function! s:CustomDiffAlgComplete(A,L,P)
        return "myers\nminimal\ndefault\npatience\nhistogram"
    endf
    command! -nargs=1 -complete=custom,s:CustomDiffAlgComplete CustomDiff :cd $TEMP | let &diffexpr='EnhancedDiff#Diff("git diff", "--diff-algorithm=<args>")'|:diffupdate
endif

Of course once I cd again (or immediately if I had autochdir enabled), then it's broken again.

NeoVim compatibility

Hi,

with Neovim 0.1.5 I get

The EnhancedDiff Plugin needs at least a Vim version 8.0

although it should have the same capabilities, right?

Can't change diff algorithm

Just installed the plugin and tried it inside a git repository with git difftool HEAD~2 HEAD~. In the first file that I've tried :EnhacedDiff <any-algorithm>, the diff style didn't change (tried many times), but when following for the next file in the changeset, the diff algorithm applied, nor did it get change for any of the following files in the changeset.

Vim 7.4.1016, Git 2.7.0. Using inside TMUX on Archlinux.

Creating unnecesary temporary files and or duplicate work slows down opening many diffs

Hi! I have a setup whereby I diff many pairs of files in the same Vim buffer. The process goes more or less like this:

$ vim -"special diff mode" : $file1 $file2 : $file3 $file4 : ...

The "special diff mode" script basically opens every pair of files in a two buffers and puts them in diff mode. These files are immutable in my case.

I noticed that it's very slow for many pairs of files, so I used execsnoop(1). The following appears to be the "core" of diffing two files:

 27327 /bin/zsh -c (git diff --diff-algorithm=patience -U0 /tmp/vWllDdr/71 /tmp/vWllDdr/72) >/tmp/vWllDdr/74 2>&1
 27327 /bin/zsh -c (git diff --diff-algorithm=patience -U0 /tmp/vWllDdr/71 /tmp/vWllDdr/72) >/tmp/vWllDdr/75 2>&1

It seems at least one of those two is redundant (if tempfiles 71 and 72 are not changed in between, that is). I'm also not sure why /tmp/vWllDdr/71 and /tmp/vWllDdr/72 are used as sources at all. The real immutable files should be openable immediately. This might have something do with with the way this multi-buffer setup I mentioned above is done. The relevant part:

let s:idx = 0
while s:idx < argc()
  if s:idx != 0
      tabnew
  endif
  execute 'silent edit ' fnameescape(argv(s:idx))
  execute 'silent ' s:vertical_modifier ' diffsplit ' fnameescape(argv(s:idx + 1))
  wincmd =
  let s:idx += 2
endwhile

Perhaps I'm doing something wrong here? Can I somehow mark those files as readonly when loading them into buffers such that vim doesn't attempt to make a copy?

Later I'll test with all of my plugins disabled, to see if there might be something else causing the duplication. I just wanted to collect my thoughts.

Another obvious way of speeding this up would be to run all of these things in parallel, but I don't think Vim supports such a thing.

Another possible source of slowness that I haven't benchmarked: starting a shell for every command (zsh -c).

Typo

I believe the option should be "set diffopt+=internal,algorithm:patience" and
not "set diffopt+=internal,algorithm=patience"

How to achieve filler lines from README images

Just a question.

I noticed in the images on the README, the filler lines look like they are using the character as apposed to the default - character. Did you do anything special to achieve that?

Sorry for raising an issue to ask this. Didn't know how to ask otherwise.

Thanks

Got "E97: cannot create diffs"

I am use the latest vim-diff-enhanced. And use Plug to manage the plugins.

The error message when I run 'PatienceDiff' and any other commands in this plugin.

Searching for "/usr/local/google/home/hqian/.vim/plugged/vim-diff-enhanced/autoload/EnhancedDiff.vim"
chdir(/usr/local/google/home/hqian/.vim/plugged/vim-diff-enhanced/autoload)
fchdir() to previous dir
sourcing "/usr/local/google/home/hqian/.vim/plugged/vim-diff-enhanced/autoload/EnhancedDiff.vim"
finished sourcing /usr/local/google/home/hqian/.vim/plugged/vim-diff-enhanced/autoload/EnhancedDiff.vim
calling function EnhancedDiff#Diff
calling function EnhancedDiff#Diff..<SNR>166_DiffInit
calling function EnhancedDiff#Diff..<SNR>166_DiffInit..<SNR>166_ModifyPathAndCD
function EnhancedDiff#Diff..<SNR>166_DiffInit..<SNR>166_ModifyPathAndCD returning '/tmp/vCmMcn3/39'
continuing in function EnhancedDiff#Diff..<SNR>166_DiffInit
calling function EnhancedDiff#Diff..<SNR>166_DiffInit..<SNR>166_ModifyPathAndCD
function EnhancedDiff#Diff..<SNR>166_DiffInit..<SNR>166_ModifyPathAndCD returning '/tmp/vCmMcn3/40'
continuing in function EnhancedDiff#Diff..<SNR>166_DiffInit
function EnhancedDiff#Diff..<SNR>166_DiffInit returning #0
continuing in function EnhancedDiff#Diff
Calling shell to execute: "(git diff --diff-algorithm=patience -U0 /tmp/vCmMcn3/39 /tmp/vCmMcn3/40) >/tmp/vCmMcn3/42 2>&1"

calling function EnhancedDiff#Diff..<SNR>166_ModifyPathAndCD
function EnhancedDiff#Diff..<SNR>166_ModifyPathAndCD returning '\-'
continuing in function EnhancedDiff#Diff
calling function EnhancedDiff#Diff..EnhancedDiff#ConvertToNormalDiff
function EnhancedDiff#Diff..EnhancedDiff#ConvertToNormalDiff returning []
continuing in function EnhancedDiff#Diff
function EnhancedDiff#Diff returning #0
E97: Cannot create diffs

diff moved lines

Could you add an algorithm that diffs moved lines?

I'm thinking Notepad++ Compare plugin. I haven't found a similar implementation for unix/linux in general, nor for vim in particular.

Notepad++ Compare plugin screenshot

test.sh fails when vim-diff-enhanced is installed by Vundle

I've installed the plugin and when I try to run the test.sh script, it looks in ~/.vim/plugin for the EnhancedDiff.vim file which, for me at least, actually exists in ~/.vim/bundle/vim-enhanced-diff/plugin

I don't know the general way to fix this as I don't know where all the other plugin managers might also stick the .vim file or I'd try to fix this myself and send you a pull request. Maybe you didn't mean for this to be used by other users?

Also, you've misspelled "readable" as "readabile" on line 27 of EnhancedDiff.txt.

Thanks very much for all your contributions to the vim world!

readme corrections

Hello,

This plugin allows to make use of the Patience diff algorithm for generating diffs to use with Vim.

Probably mean:

This plugin allows you to make use of the Patience diff algorithm for generating diffs to use with Vim.

You can also customize you setup

your setup

Is it really :CustomDiff histogram or :EnhancedDiff <algorithm> as mentioned further below?

Note: Those 2 commands use internally git to generate the diffs.

Probably needs revising. Are you saying git is used internally to generate the diffs?

consider "namespacing" the commands

PatienceDiff, DisableEnhancedDiff, CustomDiff, all have different prefixes. Plugins are more usable and discoverable if they namespace their commands, e.g.:

Ediff
EdiffPatience
EdiffDisable
EdiffCustom
...
  • This also helps users intuit which command comes from where, without having to dig through the documentation after seeing a command appear in wildmenu.
  • Instead of polluting the completion space of C, P, D, etc., the plugin only pollutes one prefix space: E. wildmenu is less useful if each plugin creates a bunch of random non-namespaced command names.

PatienceDiff crashes on Vim 7.4.52

I'm running Ubuntu 14.04 with vim 7.4, patches 1-52 (the default from the Ubuntu 14.04 repo). I have git 2.3.2 installed. vim-diff-enhanced was installed with junegunn/vim-plug.

Running running :PatienceDiff (or any other diff) results in the following error:

Error detected while processing function EnhancedDiff#Diff:
line   12:
E117: Unknown function: systemlist
E15: Invalid expression: systemlist(s:diffcmd. ' '. join(s:diffargs, ' '))
line   22:
E121: Undefined variable: difflist
E116: Invalid arguments for function empty(difflist) && difflist[0] !~# '^\%(\d\+\)\%(,\d\+\)\?[acd]\%(\d\+\)\%(,\d\+\)\?'
E15: Invalid expression: !empty(difflist) && difflist[0] !~# '^\%(\d\+\)\%(,\d\+\)\?[acd]\%(\d\+\)\%(,\d\+\)\?'
line   26:
E121: Undefined variable: difflist
E116: Invalid arguments for function writefile
E810: Cannot read or write temp files
E97: Cannot create diffs

It looks like systemlist was added in vim 7.4.248, but that's not indicated as a requirement in the docs. Perhaps the best solution is to list the minimum vim version?

Diff pattern don't work or I don't understand how it works

As an example, let the following two buffers:

contextr

When I run the following:

EnhancedDiffIgnorePat ^e.*
EnhancedDiff default

I would expect the first line to be ignored. But nothing changes in the buffers.

Whatever the expression I use, it does nothing.

The diff variable does have something in it:

g:enhanced_diff_ignore_pat [['^e.*' 'XXX']]

But whatever I do, it doesn't apply any filter. I also tried :diffupdate, but it doesn't change anything.

Also the usage seems a bit clunky. Each time I run the command EnhancedDiffIgnorePat ^e.*, I would expect the diff to update dynamically. Is it supposed to do that?

Overall, it seems like every command just does nothing. The only thing I've seen the plugin do in a consistent manner is the fact the variable g:enhanced_diff_ignore_pat is updated after using the command EnhancedDiffIgnorePat. Other than that, nothing works. May be I'm missing something in the doc? I don't see it.

Info

  • Plugin version: Version: 0.3 Thu, 05 Mar 2015 08:11:46 +0100

  • Git version: 2.32.0

  • Vim version:

    VIM - Vi IMproved 8.2 (2019 Dec 12, compilé May 28 2021 06:58:52)
    Rustines incluses : 1-2891
    Compilé par Arch Linux
    Énorme version avec interface graphique GTK3.
      Fonctionnalités incluses (+) ou non (-) :
      +acl               -farsi             +mouse_sgr         +tag_binary
      +arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
      +autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
      +autochdir         +float             +mouse_xterm       +tcl/dyn
      -autoservername    +folding           +multi_byte        +termguicolors
      +balloon_eval      -footer            +multi_lang        +terminal
      +balloon_eval_term +fork()            -mzscheme          +terminfo
      +browse            +gettext           +netbeans_intg     +termresponse
      ++builtin_terms    -hangul_input      +num64             +textobjects
      +byte_offset       +iconv             +packages          +textprop
      +channel           +insert_expand     +path_extra        +timers
      +cindent           +ipv6              +perl/dyn          +title
      +clientserver      +job               +persistent_undo   +toolbar
      +clipboard         +jumplist          +popupwin          +user_commands
      +cmdline_compl     +keymap            +postscript        +vartabs
      +cmdline_hist      +lambda            +printer           +vertsplit
      +cmdline_info      +langmap           +profile           +virtualedit
      +comments          +libcall           +python/dyn        +visual
      +conceal           +linebreak         +python3/dyn       +visualextra
      +cryptv            +lispindent        +quickfix          +viminfo
      +cscope            +listcmds          +reltime           +vreplace
      +cursorbind        +localma
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.