andrewradev / linediff.vim Goto Github PK
View Code? Open in Web Editor NEWA vim plugin to perform diffs on blocks of code
Home Page: http://www.vim.org/scripts/script.php?script_id=3745
License: MIT License
A vim plugin to perform diffs on blocks of code
Home Page: http://www.vim.org/scripts/script.php?script_id=3745
License: MIT License
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.
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?!
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
.
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
.
When reading the README it's not clear what the end result will look like. An animated gif would be even more helpful (example).
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.
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...
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!
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
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
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!
Is there any setting for vertical splitting?
Would it make sense to add vim-repeat support to this project? Seems useful as :Linediff is generally called twice in a row.
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
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
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:
def one
two
end
def two
three
end
something at the end of the file
:1,3fold
:5,7fold
V
on the closed fold!)::1,3Linediff
:5,7Linediff
Result (at least for me):
Undo seems to clear buffer contents regardless of previous edits. Is that something to be avoided?
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.
It would be nice if we could specify diffopts that apply only for linediff (like iwhite).
something like linediff_diffopt += iwhite
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.