On Thu, 17 Apr 2025 at 11:35, DwigtArmyOfChampions < dwightarmyofchampi...@hotmail.com> wrote:
> I have two buffers open in vim. I want to compare a subroutine that's > present in both buffers for differences. I don't care about the rest of the > two files, they're very different. I only care about this subroutine. Is > there an easy way to diff just this part of the code? I could go into > Visual mode, yank the subroutine of buffer1, create a new file in my temp > directory called sub_buffer1.txt, Put the code, save it, then switch to > buffer2, go to visual mode, yank that buffer's subroutine code, create a > new file in my temp directory called sub_buffer2.txt, Put that code, save > it, exit Vim, then run vimdiff on sub_buffer1.txt and sub_buffer2.txt. Is > there an easier way? > The two thoughts that occurred to me off the cuff were: 1. You don't need to save the files - vim will do a diff on a buffer. So you can do :vnew a couple of times, copy the bits you're interested in into the two new buffers, then do :diffthis on each. No mucking around with temporary directories/files. 2. Alternatively, you could diff the entire files with something like BeyondCompare and use the "Align With" function (F7) to tell it to align the start of each block for diffing (select the first line in the block on the left file, hit F7, then click on the first line of the block on the second file). That would mean there would be loads of changes you could ignore and then a block that it compared nicely. As far as I know, Vim doesn't have the equivalent of BeyondCompare's "Align With", but I could be wrong. If there's a way to do #2 in Vim, I'd be very interested, but for any serious diffing I tend to reach for BeyondCompare anyway. Al -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/CAOaJ26QERp1B1epFGwR-4_RouL4W9EfDTg8z9JwGSY-3vUNXWQ%40mail.gmail.com.