dotfiles/.vim/pack/plugins/start/vim-diffchar/doc/diffchar.txt
2024-12-15 14:45:59 +01:00

310 lines
14 KiB
Plaintext

*diffchar.txt* Highlight the exact differences, based on characters and words
>
____ _ ____ ____ _____ _ _ _____ ____
| | | || || || || | | || _ || _ |
| _ || || __|| __|| || | | || | | || | ||
| | | || || |__ | |__ | __|| |_| || |_| || |_||_
| |_| || || __|| __|| | | || || __ |
| || || | | | | |__ | _ || _ || | | |
|____| |_||_| |_| |_____||_| |_||_| |_||_| |_|
<
Last Change: 2024/02/14
Version: 9.7 (on or after patch-8.1.1418 and nvim-0.5.0)
Author: Rick Howe (Takumi Ohtani) <rdcxy754@ybb.ne.jp>
Copyright: (c) 2014-2024 Rick Howe
License: MIT
-----------------------------------------------------------------------------
INTRODUCTION *diffchar*
This plugin has been developed in order to make diff mode more useful. Vim
highlights all the text in between the first and last different characters on
a changed line. But this plugin will find the exact differences between them,
character by character - so called DiffChar.
For example, in diff mode: (`-`:`hl-DiffText` / |+|:|hl-DiffAdd|)
+-------------------------------------------------+
|The `quick brown fox jumps over the lazy` dog. |
| `-----------------------------------` |
|~ |
+-------------------------------------------------+
|The `lazy fox jumps over the quick brown` dog. |
| `-----------------------------------` |
|~ |
+-------------------------------------------------+
This plugin will exactly show the changed and added units:
+-------------------------------------------------+
|The `quick` |brown| fox jumps over the `lazy` dog. |
| `-----` |++++++| `----` |
|~ |
+-------------------------------------------------+
|The `lazy` fox jumps over the `quick` |brown| dog. |
| `----` `-----` |++++++| |
|~ |
+-------------------------------------------------+
Sync with diff mode ~
This plugin will synchronously show/reset the highlights of the exact
differences as soon as the diff mode begins/ends. And the exact differences
will be kept updated while editing.
Diff unit ~
This plugin shows the diffs based on a |g:DiffUnit|. Its default is 'Word1'
and it handles a \w\+ word and a \W character as a diff unit. There are other
types of word provided and you can also set 'Char' to compare character by
character. In addition, you can specify one or more diff unit delimiters, such
as comma (','), colon (':'), tab ("\t"), and HTML tag symbols ('<' and '>'),
and also specify a custom pattern in the |g:DiffUnit|.
Diff matching colors ~
In diff mode, the corresponding |hl-DiffChange| lines are compared between two
windows. As a default, all the changed units are highlighted with
|hl-DiffText|. You can set |g:DiffColors| to use more than one matching color
to make it easy to find the corresponding units between two windows. The
number of colors depends on the color scheme. In addition, |hl-DiffAdd| is
always used for the added units and both the previous and next character of
the deleted units are shown in bold/underline.
Diff pair visible ~
While showing the exact differences, when the cursor is moved on a diff unit,
you can see its corresponding unit highlighted with |hl-Cursor|,
|hl-TermCursor|, or similar one in another window, based on a
|g:DiffPairVisible|. If you change its default, the corresponding unit is
echoed in the command line or displayed in a popup/floating window just below
the cursor position or at the mouse position. Those options take effect on
`:diffupdate` command as well.
Jump to next/prev diff unit ~
You can use `]b` or `]e` to jump cursor to start or end position of the next
diff unit, and `[b` or `[e` to the start or end position of the previous unit.
Get/put a diff unit ~
Like line-based `:diffget`/`:diffput` and `do`/`dp` vim commands, you can use
`<Leader>g` and `<Leader>p` commands in normal mode to get and put each diff
unit, where the cursor is on, between 2 buffers and undo its difference. Those
keymaps are configurable in your vimrc and so on.
Check diff lines locally ~
When the diff mode begins, this plugin locally checks the |hl-DiffChange|
lines in the limited range of the current visible and its upper/lower lines of
a window. And each time a cursor is moved on to another range upon scrolling
or searching, those diff lines will be checked in that range. Which means,
independently of the file size, the number of lines to be checked and then the
time consumed are always constant.
Tab page individual ~
This plugin works on each tab page individually. You can use a tab page
variable (t:), instead of a global one (g:), to specify different options on
each tab page. Note that this plugin can not handle more than two diff mode
windows in a tab page. If it would happen, to prevent any trouble, all the
highlighted units are to be reset in the tab page.
Follow 'diffopt' option ~
This plugin supports "icase", "iwhite", "iwhiteall", and "iwhiteeol" in the
'diffopt' option. In addition, when "indent-heuristic" is specified,
positioning of the added/deleted diff units is adjusted to reduce the number
of diff hunks and make them easier to read.
Comparison algorithm ~
To find the exact differences, this plugin uses "An O(NP) Sequence Comparison
Algorithm" developed by S.Wu, et al., which always finds an optimum sequence.
But it takes time to check a long and dissimilar line. To improve the
performance, the algorithm is also implemented in Vim9 script. In addition,
if available, this plugin uses a builtin diff function (|diff()| in vim
patch-9.1.0071 and Lua |vim.diff()| in nvim 0.6.0) and makes it much faster.
See also ~
For a range and area selectable partial comparison, see |spotdiff.vim|
(https://github.com/rickhowe/spotdiff.vim) plugin.
-----------------------------------------------------------------------------
OPTIONS *diffchar-options*
|g:DiffUnit|, |t:DiffUnit|
A type of diff unit
'Char' : any single character
'Word1' : \w\+ word and any \W single character (default)
'Word2' : non-space and space words
'Word3' : \< or \> character class boundaries (set by 'iskeyword' option)
'word' : see `word`
'WORD' : see `WORD`
'[{del}]' : one or more diff unit delimiters (e.g. "[,:\t<>]")
'/{pat}/' : a pattern to split into diff units (e.g. '/.\{4}\zs/')
|g:DiffColors|, |t:DiffColors|
Matching colors for changed units
0 : |hl-DiffText| (default)
1 : |hl-DiffText| + a few (3, 4, ...) highlight groups
2 : |hl-DiffText| + several (7, 8, ...) highlight groups
3 : |hl-DiffText| + many (11, 12, ...) highlight groups
100 : all available highlight groups in random order
[{hlg}] : a list of your favorite highlight groups
|g:DiffPairVisible|, |t:DiffPairVisible|
Visibility of corresponding diff units
0 : disable
1 : highlight with |hl-Cursor| (default)
2 : highlight with |hl-Cursor| + echo in the command line
3 : highlight with |hl-Cursor| + popup/floating window at cursor position
4 : highlight with |hl-Cursor| + popup/floating window at mouse position
-----------------------------------------------------------------------------
KEYMAPS *diffchar-keymaps*
<Plug>JumpDiffCharPrevStart (default: `[b`)
Jump cursor to the start position of the previous diff unit
<Plug>JumpDiffCharNextStart (default: `]b`)
Jump cursor to the start position of the next diff unit
<Plug>JumpDiffCharPrevEnd (default: `[e`)
Jump cursor to the end position of the previous diff unit
<Plug>JumpDiffCharNextEnd (default: `]e`)
Jump cursor to the end position of the next diff unit
<Plug>GetDiffCharPair (default: `<Leader>g`)
Get a corresponding diff unit from another buffer to undo difference
<Plug>PutDiffCharPair (default: `<Leader>p`)
Put a corresponding diff unit to another buffer to undo difference
-----------------------------------------------------------------------------
CHANGE HISTORY *diffchar-history*
Update : 9.7
* Implemented to use a new builtin |diff()| function (available on
patch-9.1.0071) to compare diff units and make it faster in vim.
Update : 9.6, 9.61
* Changed to locally but not incrementally check the limited number of the
|hl-DiffChange| lines upon scrolling or searching.
* Fixed not to use |hl-DiffText| as the first highlight group if [{hlg}] is
specified in the |g:DiffColors| option.
Update : 9.5
* Improved not to update diff unit highlighting on unchanged diff lines on the
DiffUpdated event.
* Fixed the E421 error when 'termguicolors' is off on nvim.
Update : 9.4
* Implemented to use a builtin Lua |vim.diff()| function to compare diff units
and make it faster in nvim.
Update : 9.3
* Improved to follow the 'wincolor' option and show the colors accordingly.
* Fixed to work on some color scheme in which the "g:colors_name" variable is
different from its file name.
Update : 9.2
* Fixed the plugin error when 3 or more windows turn to be diff mode.
* Fixed the issue which the new diff lines can not be incrementally found upon
scrolling on patch-9.0.0913 or later.
* Made it faster to find diff lines in a file with many lines folded.
Update : 9.1
* Added vim original 'word' and 'WORD' units, one or more unit delimiters, and
a custom pattern to split into diff units in |g:DiffUnit| option.
* Improved to redraw diff units whenever the ColorScheme event happens when
multiple matching colors are being used (0 < |g:DiffColors|).
* Changed the category of |g:DiffColors| option as a few, several, and many
numbers of matching colors, depending on the loaded color scheme.
* Added a list of your favorite highlight groups in |g:DiffColors| option.
Update : 9.01
* Fixed to work on a |hl-Diff| highlighting group even if it is linked.
Update : 9.0
* Enhanced to make diff units easier to read when "indent-heuristic" is
specified in the 'diffopt' option.
* Improved to update diff units using `:diffupdate` command when |g:DiffUnit|,
|g:DiffColors|, and |g:DiffPairVisible| options are modified.
* Updated to check a new WinScrolled event (patch-8.2.4713) to incrementally
find scrolled diff lines.
* Implemented the comparison algorithm and diff unit highlighting in Vim9
script and made them 10 times faster on patch-8.2.3965 or later.
* Made this plugin available on or after patch-8.1.1418 and nvim-0.5.0.
Update : 8.91
* Updated to check a new WinClosed event (patch-8.2.3591) to appropriately
reset or repair the highlighted DiffChar units when a window is closed.
Update : 8.9
* Fixed not to overrule syntax highlighting.
* Fixed to successfully sync with diff mode even without patch-8.1.414.
* Changed the highlighting groups used in |g:DiffColors| option.
Update : 8.8
* Changed the highlighting groups used in |g:DiffColors| option, to completely
highlight a changed diff unit and to make each unit more visible.
* Changed to use |hl-Cursor|, |hl-TermCursor|, or similar one, as appropriate,
to highlight a corresponding diff unit, for |g:DiffPairVisible| option.
* Fixed to use proper |hl-Diff| highlighting groups even if they are linked.
* Optimized how to draw each unit and then improved performance.
Update : 8.7
* Enhanced |g:DiffPairVisible| option to show a corresponding diff unit as
well in a floating window on nvim, if its value is 3, and show a popup (not
a balloon) window at the mouse position, if its value is 4.
* Improved performance, use the external diff command together if available,
if there are so many diff units included in a line or it has taken much time
in a diff session.
* Removed |g:DiffMaxLines| option, and locally checks the limited number of
the |hl-DiffChange| lines and incrementally checks them upon scrolling or
searching.
* Removed |g:DiffModeSync| option, and always synchronize with the diff mode.
* `:SDChar`, `:RDChar`, `:TDChar`, and `:EDChar` commands are still available
but deprecated.
Update : 8.6
* Enhanced |g:DiffPairVisible| option to show a corresponding diff unit as a
popup-window just below the cursor position (available on patch-8.1.1391).
And changed its default as 1 (diff unit highlighting only).
* Fixed not to stop monitoring the changes of text and 'diffopt' option,
even if there is no |hl-DiffChange| line, when |g:DiffModeSync| option is
enabled.
Update : 8.5
* Enhanced to show a balloon on GUI and display a corresponding diff unit,
where the mouse is pointing, if |g:DiffPairVisible| option is enabled
(patch-8.1.647 is required to correctly display multibyte characters).
* Fixed to correctly handle |hl-DiffChange| lines while editing.
Update : 8.4
* Extended |g:DiffMaxLines| option to allow a negative value as multiples of
the window height and changed its default as -3.
* Fixed to reset all highlighted DiffChar units when more than two windows
become diff mode in a tab page.
* Deleted |g:DiffSplitTime| option.
Update : 8.3
* Fixed not to detect more |hl-DiffChange| lines than |g:DiffMaxLines| option.
Update : 8.2
* Fixed to correctly update the highlighted DiffChar units while editing when
a new internal diff is not specified in 'diffopt' option (patch-8.1.360).
Update : 8.1
* Fixed to properly detect |hl-DiffChange| lines even when all visible lines
of current window are in a closed fold if a |g:DiffMaxLines| option is
enabled.
Update : 8.0
* Introduced a |g:DiffMaxLines| option to dynamically detect a limited number
of |hl-DiffChange| lines, when the diff mode begins and whenever a cursor is
moved onto an undetected line. It enables to always take a minimum constant
time, independently of the file size.
* Enhanced to check a new DiffUpdated event (patch-8.1.397) to follow diff
updates and some changes of 'diffopt' option.
* Enhanced to support new iwhiteall and iwhiteeol of 'diffopt' option
(patch-8.1.360).
* Removed |g:DiffUpdate| option and merged it into |g:DiffModeSync|.
* Removed keymap for <F7> and <F8>, which toggle to show/reset the highlights.
* Changed to work in diff mode, not in non-diff mode.
* Removed a support for vim version 7.x.
* Changed not to set 'diffexpr' option when a new internal diff is specified
in 'diffopt' (patch-8.1.360).
vim:tw=78:ts=8:ft=help:norl: