Giter Club home page Giter Club logo

linediff.vim's Introduction

GitHub version Build Status

The linediff plugin provides a simple command, :Linediff, which is used to diff two separate blocks of text.

Demo

A simple example:

def one
  two
end

def two
  three
end

If we mark the first three lines, starting from def one, in visual mode, and execute the :Linediff command, the signs 1- will be placed at the start and at the end of the visual mode's range. Doing the same thing on the bottom half of the code, starting from def two, will result in the signs 2- placed there. After that, a new tab will be opened with the two blocks of code in vertical splits, diffed against each other.

The two buffers are temporary, but when any one of them is saved, its original buffer is updated. Note that this does not save the original buffer, just performs the change. Saving is something you should do later.

Executing the command :LinediffReset will delete the temporary buffers and remove the signs.

Executing a new :Linediff will do the same as :LinediffReset, but will also initiate a new diff process.

For more commands and different workflows, you should read the full documentation with :help linediff

Note that you shouldn't linediff two pieces of text that overlap. Not that anything horribly bad will happen, it just won't work as you'd hope to. I don't feel like it's a very important use case, but if someone requests sensible behaviour in that case, I should be able to get it working.

linediff.vim's People

Contributors

aileot avatar andrewradev avatar dkinzer avatar hcgraf avatar lucc avatar montefra avatar somini avatar xaizek 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  avatar  avatar  avatar  avatar  avatar

linediff.vim's Issues

Error messages due to backslashes on filepaths

When opening the diff tab the plugin displayed some error messages, similar to

  Error detected while processing function <SNR>54_Linediff..<SNR>54_PerformDiff..linediff#differ#CreateDiffBuffer..linediff#differ#SetupDiffBuffer:
  line    7:
  E518: Unknown option: <corruptedFilePath>^I

This problem occurs with gVim under ms-windows, and changing line 100 of autoload/differ.vim to

 let statusline = printf('[%s:%%{b:differ.from}-%%{b:differ.to}]', 
          \ substitute(bufname(self.original_buffer), '\', '/', 'g'))

solved the issue, but I didn't tested on different systems.

Thanks for sharing this awesome plugin!

Update the buffers after creation from original file?

I know that this might be outside the scope of the plugin but I figured since it has so many nice things (like sign markers and everything) it would be cool if it could detect and sync the changes made in the source buffer.

Adjusting cursor position when diff starts

When the new tab containing the diffs opens the cursor remains at the bottom of the second window.
Possibly it would be better to have the cursor on the first difference, specially when a large number of lines is selected.

A possible solution is

  function! linediff#differ#CreateDiffBuffer(edit_command) dict
    let lines     = self.Lines()

    :
    :

    diffthis
    wincmd t
    normal! 1000[c
  endfunction

Strange errors on :Linediff

This happens on every second :Linediff, right before vimdiff opening.

"/tmp/vVwhNek/20" [New File]                                                                                                                                                                               
Error detected while processing function <SNR>20_Linediff..<SNR>20_PerformDiff..linediff#differ#CreateDiffBuffer..linediff#differ#SetupDiffBuffer:                                                         
line    7:                                                                                                                                                                                                 
"/tmp/vVwhNek/21" [New File]                                                                                                                                                                               
E492: Not an editor command: %04v][%p%%]\ [%L\ lines]                                                                                                                                                      
Press ENTER or type command to continue                          

This %04v][%p%%]\ [%L\ lines] is part of the statusline definition in my vimrc file.

Linediff specific diffopts

It would be nice if we could specify diffopts that apply only for linediff (like iwhite).

something like linediff_diffopt += iwhite

Don't work in MacVim (GUI)

Hi. I installed via vim-plug. I could use it smoothly in terminal vim. However, after I switched to mvim, it reported E149: Sorry, no help for linediff when I typed :help linediff, and reported E117: Unknown function: linediff#Linediff when I typed :Linediff.

My minimal .vimrc is:

call plug#begin('~/.vim/bundle')
Plug 'AndrewRadev/linediff.vim'
call plug#end()

macOS version: 12.4 (21F79)
MacVim version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 24 2021 14:13:28)
macOS version - x86_64
Included patches: 1-3455
Compiled by GitHub Actions
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +file_in_path      -mouse_sysmouse    +tag_binary
+arabic            +find_in_path      +mouse_urxvt       -tag_old_static
+autocmd           +float             +mouse_xterm       -tag_any_white
+autochdir         +folding           +multi_byte        -tcl
-autoservername    -footer            +multi_lang        +termguicolors
+balloon_eval      +fork()            -mzscheme          +terminal
+balloon_eval_term +fullscreen        +netbeans_intg     +terminfo
+browse            +gettext           +num64             +termresponse
++builtin_terms    -hangul_input      +odbeditor         +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          +transparency
+cmdline_compl     +keymap            +postscript        +user_commands
+cmdline_hist      +lambda            +printer           +vartabs
+cmdline_info      +langmap           +profile           +vertsplit
+comments          +libcall           +python/dyn        +virtualedit
+conceal           +linebreak         +python3/dyn       +visual
+cryptv            +lispindent        +quickfix          +visualextra
+cscope            +listcmds          +reltime           +viminfo
+cursorbind        +localmap          +rightleft         +vreplace
+cursorshape       +lua/dyn           +ruby/dyn          +wildignore
+dialog_con_gui    +menu              +scrollbind        +wildmenu
+diff              +mksession         +signs             +windows
+digraphs          +modify_fname      +smartindent       +writebackup
+dnd               +mouse             -sodium            -X11
-ebcdic            +mouseshape        -sound             -xfontset
+emacs_tags        +mouse_dec         +spell             +xim
+eval              -mouse_gpm         +startuptime       -xpm
+ex_extra          -mouse_jsbterm     +statusline        -xsmp
+extra_search      +mouse_netterm     -sun_workshop      -xterm_clipboard
-farsi             +mouse_sgr         +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_DARWIN -g -O2 -arch x86_64 -arch arm64 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wall -Wextra -Wshadow -Werror -Wno-error=missing-field-initializers -Wno-error=deprecated-declarations -Wno-error=unused-function
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib -arch x86_64 -arch arm64 -L/usr/local/lib -o Vim -lm -lncurses -liconv /usr/local/lib/libintl.a -framework AppKit -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE

Improvement: diff multiple blocks

Hi,

I have an idea for an improvement, which might hopefully be quite easy to implement (however, I didn't have time to look at the actual implementation myself, yet).

It would be great to be able to diff more than two blocks of code. VIM is actually capable of up to 8(!) buffers in diff mode (see :help E96).

So maybe keep the normal :Linediff as usual, but add some lower level commands like e.g. :LinediffAdd to add a new block (from 1-8), and then :LinediffDo or :LinediffShow to create the diff tab.

At the moment, I'm doing this procedure manually, but especially Linediff's feature of copying back the changes would be really great :)

Regards
Hagen

Provide keybindings to jump between differences

On longer lines (e.g. in logfiles) it may be hard to spot the differences even if they are highlighted.
It would therefore be nice to have some keybindings to jump to the next/prev difference, like ]d and [d.

Lineedit command?

Sometimes it is useful to edit part of a buffer in a new temporary buffer, e.g. to run a linter against a docstring.
Linediff can be abused for this (by diffing the same section against itself), but a separate :Lineedit command would be better.

Or is there a better way in general?!

Problem with folds

Hi,

when working with this (btw. very great) plugin and very big files, I found the following bug:
Because my blocks to compare are very long, it's convenient to fold them first and then do the Linediff.
That causes Linediff to remove the end of the file (i.e. after the second block).

I'll do a step by step example:

  • Open vim with an empty buffer. Type / paste the following code:
def one
  two
end

def two
  three
end

something at the end of the file
  • Fold the two blocks of codes (vim ex commands):
:1,3fold
:5,7fold
  • Select each block for Linediff (the cool thing is, this works with V on the closed fold!):
:1,3Linediff
:5,7Linediff
  • Change something in the second (right) diff-buffer, and save it

Result (at least for me):

  • The change is correctly copied to the original buffer (that's good)
  • The fold is gone (that's not perfect but ok)
  • The text after the second fold is gone (that's the bug ;-) )

Show LineDiff Automatically in Merge Files

Do you think it is possible that if I'm within an merge file and call Linediff from within a section like the following one, that the lines to diff are determined automatically?

<<<<<<< HEAD
one
two
=======
one+three
two times 4
>>>>>>> 23140808afdeh290325

That would be great!

Undo changes

Undo seems to clear buffer contents regardless of previous edits. Is that something to be avoided?

Vim patch 9.0.907 causes E1312 when temporary buffers are closed

Vim changed its behavior at patch 9.0.907 to prohibit autocommands from performing certain operations such as closing buffers. Consequently, closing a linediff temporary buffer now prints an error message like this one:

Error detected while processing WinEnter Autocommands for "<buffer=3>"..function linediff#controller#Destroy[6]..linediff#differ#CloseAndReset[1]
..linediff#differ#CloseDiffBuffer:
line 3:
E1312: Not allowed to change the window layout in this autocmd

A workaround is to change line 214 of autoload/linediff/differ.vim (in function linediff#differ#CloseDiffBuffer(()) from

exe "bdelete".bang." ".self.diff_buffer

to

call feedkeys(":bdelete".bang." ".self.diff_buffer."<CR>:<BS>")

which just executes the :bdelete command in a feedkeys() operation, clearing the :bdelete from the command line with a colon and a backspace.

Doesn't work with different source files.

I have Linediff installed with latest Vundle, in Mac OS X, vim 8.0, and when I issue :Linediff in the second block of text (on second file), the diff window appears with the left buffer totally empty, in red...

diff tab remains open after LinediffReset

I just noticed that after executing :LinediffReset the new tab remains open.
This new behavior can be tracked to changes on PerformDiff() on commit c07c7c6.

:LinediffReset attempt to close both buffers,

  function! s:LinediffReset()
    call s:differ_one.CloseAndReset()
    call s:differ_two.CloseAndReset()
  endfunction

  function! linediff#differ#CloseDiffBuffer() dict
    if bufexists(self.diff_buffer)
      exe "bdelete ".self.diff_buffer
    endif
  endfunction

, but after the first buffer is closed the BufUnload event trigger and reset
both entries, so the second call to bufexists() has an invalid argument: -1.

I didn't understand very well the changes on that commit, but maybe it is possible to change only the second autocmd BufUnload.

E97: Cannot create diffs

Hi

I clone your repository and try to compare the two following lines:
Toto
Tutu

I get the following error;
Error detected while processing function 20_Linediff..20_PerformDiff..linediff#differ#CreateDiffBuffer:
line 26:
E97: Cannot create diffs
Press ENTER or type command to continue

And then diff doesn't show diff

I notice that vimdiff raise same error now

Regards,

Arnaud

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.