rickhowe / spotdiff.vim

A range and area selectable diffthis to compare partially
http://www.vim.org/scripts/script.php?script_id=5509
MIT License
41 stars 5 forks source link
diff vim vim-plugin vimdiff

spotdiff.vim

A range and area selectable :diffthis to compare partially

Vim provides a diff mode which is useful to see differences between windows. However, it always shows the differences for entire line. And it can not compare a sequence of words within a line, and sentences and paragraphs which are separated into several lines.

To compare partially everywhere in any window, this plugin provides two groups of commands, which are alternative to vim original :diffthis, :diffoff, and :diffupdate. One is for which allows to select a range of lines in diff mode. Another is for which allows to select the Visual, motion, and text object area in non-diff normal mode. Both work independently in a tab page.

Selecting a range of lines

There are :Diffthis, :Diffoff, and :Diffupdate commands available.

You can use :Diffthis to specify a range of lines to be compared. And can use :Diffoff to reset and :Diffupdate to update the differences.

Do not use vim original diff commands together with this plugin's ones. Try :Diffoff! to reset all in a trouble.

If you have installed diffchar.vim plugin, you can see the exact differences and use their options and keymaps.

Commands

Demo

demoRS

Selecting the Visual, motion, and text object area

There are :VDiffthis, :VDiffoff, and :VDiffupdate commands available.

You can use :VDiffthis to specify the Visual area to be compared. And can use :VDiffoff to reset and :VDiffupdate to update the differences. Note that those commands work in non-diff normal mode.

While showing the exact differences, when the cursor is moved on a difference unit, you can see its corresponding unit highlighted in hl-Cursor, according to the g:DiffPairVisible option.

You can use ]b or ]e to jump cursor to start or end position of the next difference unit, and [b or [e to the start or end position of the previous unit.

This plugin provides the corresponding mappings to those commands, such as <Plug>(VDiffthis) and <Plug>(VDiffoff). As a default, <Leader>t and <Leader>o keys are mapped to them and, for example, v$<Leader>t selects the text from the current cursor position to the end of line and 3vis<Leader>t selects the next 3 sentences as the Visual area. And <Leader>o clears the selected area.

In addition to selecting the Visual area, you can use <Leader>t as a custom operator followed by a motion or a text object command, which will set those selected area as the Visual one and then call :VDiffthis. For example, <Leader>t$ and <Leader>t3is work same as above examples.

Commands

Options

These options are same as those used in the diffchar.vim plugin.

Keymaps

These keymaps are same as those used in the diffchar.vim plugin.

Mapping Default Key Description
<Plug>JumpDiffCharPrevStart [b Jump cursor to the start position of the previous diff unit
<Plug>JumpDiffCharNextStart ]b Jump cursor to the start position of the next diff unit
<Plug>JumpDiffCharPrevEnd [e Jump cursor to the end position of the previous diff unit
<Plug>JumpDiffCharNextEnd ]e Jump cursor to the end position of the next diff unit

These keymaps are used only in this plugin.

Mapping Default Key Description
<Plug>(VDiffthis) <Leader>t Call :VDiffthis for the visually selected area
Set the selected motion and text object area as the Visual one and then call :VDiffthis
<Plug>(VDiffthis!) <Leader>T Call :VDiffthis! for the visually selected area
Set the selected motion and text object area as the Visual one and then call :VDiffthis!
<Plug>(VDiffoff) <Leader>o Call :VDiffoff in the current window
<Plug>(VDiffoff!) <Leader>O Call :VDiffoff! in the current tab page
<Plug>(VDiffupdate) <Leader>u Call :VDiffupdate in the current tab page

Demo

demoVS