Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks!

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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 :windo diffthis).

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

:help [range]
:help V

Using the NrrwRgn plugin to solve your example, you would put the cursor on line 2 of fileA and type

Vjj\nr

to visually-select lines 2-4 (Vjj) and copy them to a new buffer (\nr). Then put the cursor on line 8 of fileB and repeat the same sequence. In each of the two new buffers, execute

:diffthis

Not elegant, but it works.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.