diffchar.vim icon indicating copy to clipboard operation
diffchar.vim copied to clipboard

some comments and suggestion..

Open Shane-XB-Qian opened this issue 4 years ago • 7 comments

Hi... looks this is a good enhancement (with your another 'spotdiff.vim') vs native vimdiff // we can see really sometime can not clearly show what chars were different in a line.. // native vimdiff looks compared by line (due to 'patient' algo?!) // sometime not clear the isk/diff unit, but just the diff in a line..

though it had advantage also, if appended a 'o' to 'fo', maybe just like to show the 'o' was the diff, not the whole word 'foo'.

  • so is it possible to offer a command to toggle this 2 compare ways?
  • looks hl a bit inconsistent with native, e.g added '123' into 'foo.123.foo', should hl as 'difftext' or 'diffadd'?
  • like #21, and that ticket probably suggested to offer an option to disable those mappings, anyhow if no want those..

so far just a rough feeling, maybe others...... and sorry if bother...........

Shane-XB-Qian avatar Feb 19 '21 14:02 Shane-XB-Qian

so is it possible to offer a command to toggle this 2 compare ways?

g:DiffUnit can be used to change a diff unit like 'Char' and 'Word1'. You can define a command to toggle between them:

command! CDU if &diff | let &diff = 0 | let g:DiffUnit = (g:DiffUnit == 'Word1') ? 'Char' : 'Word1' | let &diff = 1 | endif

looks hl a bit inconsistent with native, e.g added '123' into 'foo.123.foo', should hl as 'difftext' or 'diffadd'?

When g:DIffUnit = 'Word1' and comparing '123' and 'foo.123.foo', the first 'foo.' and the last '.foo' are highlighted in DiffAdd. Original vim never uses DiffAdd in a changed line, though.

like #21, and that ticket probably suggested to offer an option to disable those mappings, anyhow if no want those..

I just followed a sample plugin described in :h write-plugin for keymap. My plugin does not map the key such as <Leader>g if it has already defined.

rickhowe avatar Feb 20 '21 03:02 rickhowe

so is it possible to offer a command to toggle this 2 compare ways?

g:DiffUnit can be used to change a diff unit like 'Char' and 'Word1'. You can define a command to toggle between them:

command! CDU if &diff | let &diff = 0 | let g:DiffUnit = (g:DiffUnit == 'Word1') ? 'Char' : 'Word1' | let &diff = 1 | endif

oh.. good.. but looks that's not exactly like native way, to complex code content, sometime native way had advantage.

When g:DIffUnit = 'Word1' and comparing '123' and 'foo.123.foo', the first 'foo.' and the last '.foo' are highlighted in DiffAdd. Original vim never uses DiffAdd in a changed line, though.

the hl of 'diffadd' by that looks confused with added lines, perhaps better to keep like native 'difftext', IMO.

like #21, and that ticket probably suggested to offer an option to disable those mappings, anyhow if no want those..

I just followed a sample plugin described in :h write-plugin for keymap. My plugin does not map the key such as <Leader>g if it has already defined.

yea, i see, but problem is user perhaps did not map one, meantime he/she Not like to get be mapped by this plugin either. // he/she may like self-control it..

Shane-XB-Qian avatar Feb 20 '21 06:02 Shane-XB-Qian

IMO: this plugin had advantage when to compare text style content, and with your another 'spotdiff.vim' plugin, to compare by range by needing had much useful. though if there was a toggle cmd to enable or issue this feature, but not by default would be better. mostly due to native way had advantage too, or user perhaps used to it..........

Shane-XB-Qian avatar Feb 20 '21 06:02 Shane-XB-Qian

Please use g:DiffModeSync option and :TDChar command, which are deprecated but still available. The following is from Readme document of version 8.6:

This plugin will synchronously show/reset the highlights of the exact differences as soon as the diff mode begins/ends since a |g:DiffModeSync| is enabled as a default. And the exact differences will be kept updated while editing.

You can use :SDChar and :RDChar commands to manually show and reset the highlights on all or some of lines. To toggle the highlights, use :TDChar command.

|g:DiffModeSync|, |t:DiffModeSync| Synchronously show/reset/update with diff mode 0 : disable 1 : enable (default)

:[range]SDChar Show the highlights of difference units for [range] :[range]RDChar Reset the highlights of difference units for [range] :[range]TDChar Toggle to show/reset the highlights for [range]

rickhowe avatar Feb 21 '21 08:02 rickhowe

the hl of 'diffadd' by that looks confused with added lines, perhaps better to keep like native 'difftext', IMO.

If DiffText is used instead of DiffAdd, 01 will be; 02 It looks that 'swift' is changed to 'brown' and 'brown' is changed to 'lazy'. But it is not correct.

yea, i see, but problem is user perhaps did not map one, meantime he/she Not like to get be mapped by this plugin either.

I have no good idea. If necessary, please comment out the line 49 of plugin/diffchar.vim:

48	if !hasmapto(plg, 'n') && empty(maparg(key, 'n'))
49		"execute 'nmap <silent> ' . key . ' ' . plg
50	endif
51	execute 'nnoremap <silent> ' plg . ' ' . cmd . '<CR>'

rickhowe avatar Feb 21 '21 09:02 rickhowe

It looks that 'swift' is changed to 'brown' and 'brown' is changed to 'lazy'. But it is not correct.

to me, i think user probably just care those words (if word as unit) were diff, how should i knew which were added which were just changed, meant probably just care/knew 'lazy' --> 'swift brown' at first and 'swift brown' --> 'lazy' at next. // if really wanted, then probably use another hl as long as not same like 'diffadd', since added lines use 'diffadd' also.

I have no good idea. If necessary, please comment out the line 49 of plugin/diffchar.vim

try something like this:

" Configurable Keymaps
if get(g:, 'diffchar_mapping', 0)
	for [key, plg, cmd] in [
		\['[b', '<Plug>JumpDiffCharPrevStart',
										\':call diffchar#JumpDiffChar(0, 0)'],
		\[']b', '<Plug>JumpDiffCharNextStart',
										\':call diffchar#JumpDiffChar(1, 0)'],
		\['[e', '<Plug>JumpDiffCharPrevEnd',
										\':call diffchar#JumpDiffChar(0, 1)'],
		\[']e', '<Plug>JumpDiffCharNextEnd',
										\':call diffchar#JumpDiffChar(1, 1)'],
		\['<Leader>g', '<Plug>GetDiffCharPair',
										\':call diffchar#CopyDiffCharPair(0)'],
		\['<Leader>p', '<Plug>PutDiffCharPair',
										\':call diffchar#CopyDiffCharPair(1)']]
		if !hasmapto(plg, 'n') && empty(maparg(key, 'n'))
			execute 'nmap <silent> ' . key . ' ' . plg
		endif
		execute 'nnoremap <silent> ' plg . ' ' . cmd . '<CR>'
	endfor
endif

Shane-XB-Qian avatar Feb 21 '21 10:02 Shane-XB-Qian

Please use g:DiffModeSync option and :TDChar command, which are deprecated but still available.

ideally, yea, combine those 2 and ':TDWord' and 'spotdiff.vim' To:

  • ':{range}DiffChar' and ':{range}DiffWord'
  • default use native compare way, to issue those 2 cmd to use for word/char unit just per needing, when finished, then toggle back native way or close.

// well, just my option, i felt this good for text style content compare, and by this way, would be more useful to be common usage. // but you or others may disagree, so up to you, it's ok..... :-)

Shane-XB-Qian avatar Feb 21 '21 11:02 Shane-XB-Qian

i've forgot what i said, but should be out-date anyway.. closing..

Shane-XB-Qian avatar Dec 15 '22 09:12 Shane-XB-Qian