I often need to keep several directories synchronized across two or three machines. I will periodically run diff -qr local/path mounted/remote/path > diff-list.txt to get a list of what is different and what is only present on either machine. After this runs, my current workflow is to cleanup the "diff output" then set about doing manual comparisons between the local and remote files. I cannot fully automate the synchronization or "merge" operation; some files need to be different and will always show up as part of the diff. (That's OK.)

Here's a sample line from my diff file ...

Files /home/seokor/root/src/bin/pasteboard/test/sok-info/swap.c and /mnt/diakor/root/src/bin/pasteboard/test/sok-info/swap.c differ

The pain point is this: My current workflow has diff-list.txt opened in VIM in one tmux window and a vimdiff of the two files in question opened in another tmux window. I review the differences, resolve conflicts (merge, copy/replace, ignore, ... whatever). Then I quit the vimdiff session, go back to tmux window 0, get the next pair of files, go back to tmux window 1, run vimdiff on this new pair of files ... rinse and repeat.

I want to have this: A single VIM session with three panes: left is diff-list.txt, middle and right are vimdiff-ish. As I cursor up/down in the left-most pane (the listing), when I hit <RETURN> (or some other mapping), I'd like the current line to be parsed (to extract the two file paths) and have the middle and right panes updated to open the two files then refresh the diff. Think of this as a "diff browser."

I've played a little bit with the idea and I managed to do this:

vim -O -c 'wincmd l | diffthis | wincmd l | diffthis | 2wincmd h' f1 f2 f3

Of course, files f[123] are just for experimenting, but f1 would be diff-list.txt and f2 and f3 would be pulled from the list's current line. (This test was to see if I could open VIM with three buffers and have only two of them operate as a vimdiff. And it works.)

My question: Can this be done? Can a vimscript be written that is attached only to a specific buffer (in this case, the "diff listing" buffer on the left)? Can a vimscript, after parsing the buffer's line to extract file names, "push" those file names to the other two buffers (ostensibly closing the previous files and opening the new ones), then force a diff update?

  • Yes it can be done. You can source a vimscript and set up only buffer-local mappings. Please provide the exact format of your diff-list – D. Ben Knoble May 2 at 13:46
  • Just found vim-dirdiff. Didn't try it myself, but perhaps it's useful. – Ralf May 3 at 14:15
  • @d-ben-knoble Here's a sample line from my diff file ... Files /home/seokor/root/src/bin/pasteboard/test/sok-info/swap.c and /mnt/diakor/root/src/bin/pasteboard/test/sok-info/swap.c differ – LiamF May 5 at 5:52
  • @Ralf - vim-dirdiff looks interesting! I'll look into that; thanks. – LiamF May 5 at 5:52
  • Liam, please edit your question and add the sample line there. So reader get the whole picture without reading comments. – Ralf May 5 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.