Here you can find the source code defining the
diffsplit command: vim/vim, let see what it does:
- It set some reference to the old window, as we will create a new one.
- It disable the tab opening
- Split the window (create a new window, that where the
old_curwin is useful)
- Edit the desired file
- Check that we are on a new window
- Set the diffs options for the current window
- Check the old window is still a valid window
- Set the diffs options for the old window
- Check the old buffer reference is still valid
- Change the line number to match the one of the old window.
As you can see, there is nothing in this function that change the cursor from the new window to the original one. I think the official* answer is that "it's by design that you stay on the new window".
Now, you can, as other answer suggested, use an autocommand to add the
switch to original step, I think it's the best you can do.
* From what I understand, I wont talk for the official Vim maintainers.
Why your autocomand does not work:
When you do
autocmd FilterWritePost * ...
And it is called from the
diffsplit command, both files will trigger this event (and both files will have the
&diff variable set), you can check that with the following autocommand:
:autocmd FilterWritePre * if &diff | echomsg expand('%')
I think your best solution is still to use a custom command.
I have tried to work with the following autocommand events:
But none of them gave results, because it gets triggered two times, or because it gets triggered before the buffer has the
diff option set.
Once more, I think your best solution is to use a custom command.