I often want to compare directories. I need to know which files only exist in one of them and which files differ. If any files differ, I sometimes want to see the actual change so I need an efficient way to do so.
For starters, I am using this
drq alias to diff directories:
drq expands to
diff -r -q which executes a recursive (
diff that only lists changes (
-q, i.e. quiet).
In order to inspect file changes, I use
By default, one could simply run
vimdiff file1 file2.
However, when I don’t know in advance whether the files do have differences I don’t want to actually fire up Vim unless they do.
Thus, my ~/.functions contains the following definition:
This simply first
diffs the files in question and opens Vim only if
diff finds any differences .
vd file1 file1 will just return without starting vim.
This approach causes the two files to be diff’ed twice but I rarely experience any waiting times.
(I turn off the syntax in diff view to not get distracted with
windo set syntax=off.)
Finally, I have another seemingly strange function defined:
Files is now a function which runs my previously mentioned
vd on its first and third argument.
Go back to
drq and guess ;-).
Well, once the recursive
diff told me that two files differ and I want to compare them, I can simply copy the whole line with the two files, paste it and execute it as a new command.
Files function will forward its “arguments” to vimdiff as needed.
Using Tmux in visual mode, this looks like this:
After executing the
drq A B, I have to type
prefix is the Tmux prefix, of course):
Move Jump to up Line Start Paste | | | <prefix>[k><Space>0<Enter><prefix>] | | | Open Tmux Start Copy Visual Mode Selection
This is much faster than you would expect.
Hitting Enter at this point will open up Vim and show the changes.
Instead of pressing
k, you can also jump higher with
3k for example.
You might wonder why
Files uses my custom
vd instead of plain
The only reason for that is that sometimes the files in questions have changed after the recursive
diff’s execution and this makes sure Vim is not started for no reason.