GithubHelp home page GithubHelp logo

emacs-vdiff's Introduction

vdiff

A tool like vimdiff for Emacs

Introduction

vdiff is a diff tool for Emacs that is made to behave like vimdiff, meaning diff information is displayed in buffers as you edit them. There are commands for cycling through the hunks detected by diff and applying changes from one buffer to the other. The main features are

  1. Synchronized scrolling of the buffers with lines matching between the two
  2. Commands to transmit (send/receive) hunks between buffers
  3. Automatic folding of lines that are unchanged in both buffers
  4. Commands to jump easily between hunks
  5. Everything done through overlays, meaning vdiff doesn’t alter the actual text in the buffer (unless you are transmit changes of course)
  6. Unlike ediff, remain in buffers instead of having to use a third “control buffer”
  7. Cool hydra (see below)

vdiff has not been extensively tested yet, so please report any issues you find. Contributions and suggestions are very welcome.

Screenshot

./img/leuven.png

Installation and Usage

vdiff was recently added to MELPA, which is the recommended way to install it and keep it up to date. To install it you may do M-x package-install RET vdiff RET.

After installing you can bind the commands to your preferred key prefix like this

(require 'vdiff)
(define-key vdiff-mode-map (kbd "C-c") vdiff-mode-prefix-map)

which will bind most of the commands under the C-c prefix when vdiff-mode is active. Of course you can pick whatever prefix you prefer. With the C-c prefix the commands would be

Basics

KeyCommandDescription
C-c gvdiff-switch-bufferSwitch buffers at matching line
C-c nvdiff-next-hunkMove to next hunk in buffer
C-c pvdiff-previous-hunkMove to previous hunk in buffer
C-c hvdiff-maybe-hydraEnter vdiff-hydra if defined
C-lvdiff-sync-and-centerRecenter both buffers at this line

Viewing and Transmitting Changes Between Buffers

KeyCommandDescription
C-c rvdiff-receive-changesReceive change from other buffer
C-c svdiff-send-changesSend this change(s) to other buffer
C-c fvdiff-refine-this-hunkHighlight changed words in hunk
C-c xvdiff-remove-refinements-in-hunkRemove refinement highlighting
(none)vdiff-refine-this-hunk-symbolRefine based on symbols
(none)vdiff-refine-this-hunk-wordRefine based on words
C-c Fvdiff-refine-all-hunksHighlight changed words
(none)vdiff-refine-all-hunks-symbolRefine all based on symbols
(none)vdiff-refine-all-hunks-wordRefine all based on words

Folds

KeyCommandDescription
C-c Nvdiff-next-foldMove to next fold in buffer
C-c Pvdiff-previous-foldMove to previous fold in buffer
C-c cvdiff-close-foldClose fold at point or in region
C-c Cvdiff-close-all-foldsClose all folds in buffer
C-c tvdiff-close-other-foldsClose all other folds in buffer
C-c ovdiff-open-foldOpen fold at point or in region
C-c Ovdiff-open-all-foldsOpen all folds in buffer

Ignoring case and whitespace

KeyCommandDescription
C-c i cvdiff-toggle-caseToggle ignoring of case
C-c i wvdiff-toggle-whitespaceToggle ignoring of case

Saving, Updating and Exiting

KeyCommandDescription
C-c wvdiff-save-buffersSave both buffers
C-c uvdiff-refreshForce diff refresh
(none)vdiff-restore-windowsRestore window configuration
C-c qvdiff-quitQuit vdiff

Evil-mode users might prefer something like the following to use a comma as a prefix in normal state.

(require 'vdiff)
(require 'evil)
(evil-define-key 'normal vdiff-mode-map "," vdiff-mode-prefix-map)

To start vdiff, use either vdiff-files to select two files or vdiff-buffers to select two open buffers.

Hydra (optional)

If the hydra package is loaded, vdiff-hydra is defined to allow quick movement and changes to be made in the buffer. By default it lives on the h command in the prefix map. Bind vdiff-maybe-hydra directly to customize this.

img/hydra.png

Further customization

The current customization options and there defaults are

;; Whether to lock scrolling by default when starting vdiff
(setq vdiff-lock-scrolling t)

;; external diff program/command to use
(setq vdiff-diff-program "diff")

;; Extra arguments to pass to diff. If this is set wrong, you may
;; break vdiff.
(setq vdiff-diff-program-args "")

;; Unchanged lines to leave unfolded around a fold
(setq vdiff-fold-padding 6)

;; Minimum number of lines to fold
(setq vdiff-min-fold-size 4)

;; Function that returns the string printed for a closed fold. The arguments
;; passed are the number of lines folded, the text on the first line, and the
;; width of the buffer.
(setq vdiff-fold-string-function 'vdiff-fold-string-default)

;; Default syntax table class code to use for identifying \"words\" in
;; \`vdiff-refine-this-change'. Some useful options are
;; 
;; \"w\"   (default) words
;; \"w_\"  symbols \(really words plus symbol constituents\)
;; 
;; For more information see
;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Class-Table.html
(setq vdiff-default-refinement-syntax-code "w")

;; How to represent subtractions (i.e., deleted lines). The
;; default is full which means add the same number of (fake) lines
;; as those that were removed. The choice single means add only one
;; fake line. The choice fringe means don't add lines but do
;; indicate the subtraction location in the fringe.
(setq vdiff-subtraction-style 'full)

;; Character to use for filling subtraction lines. See also
;; `vdiff-subtraction-style'.
(setq vdiff-subtraction-fill-char ?-)

emacs-vdiff's People

Contributors

gvol avatar justbur avatar purcell avatar syohex avatar

Watchers

 avatar  avatar

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.