How might one diff lines 2-4 in fileA and lines 8-10 in fileB?
Also, is it possible to visually select the lines in each file instead of writing down the line numbers?
The solution you want does not currently exist in Vim, although some developers are discussing it. There are two solutions that I've used.
One is to delete line 1 in fileA and lines 1-7 in fileB and diff the remaining lines (e.g., with
The other is to use a plugin such as NrrwRgn to copy the lines of interest to new buffers, then diff those buffers. One nice feature of the NrrwRgn plugin is that you can make changes to those new buffers and when you quit them, the changes are copied back to the original buffers.
For any Vim operation for which you can specify a range of lines, that range may be specified in several ways. One is to use line numbers. Another is to line-wise visually select the region. See
Using the NrrwRgn plugin to solve your example, you would put the cursor on line 2 of fileA and type
to visually-select lines 2-4 (
Not elegant, but it works.