I would suggest a different approach: instead of using mercurial command-line interface to view differences between files, use one of vim plugins that adds VCS support, in this case you will neither need to close anything nor do something with swap file.
For example, with my aurum you may use <leader>aD
(mapped to :AuVimDiff
) to view differences between currently opened buffer and its version in repository and then <Leader>X
to switch back to normal view (if you have not edited anything it will even restore opened/closed folds). If you do let g:aurum_vimdiffusewin=1
and use vertical or horizontal (depending on 'diffopt') equally sized splits then my script will reuse one of adjacent windows.
With <leader>agD
you can view all changes to all files in repository in a multiple tabs in a vimdiff split (excluding added and removed files): it is mapped to :AuVimDiff full
. As far as I know this functionality is almost unique: there is some script for mercurial which does the same job, but it is not integrated with other VCS plugins. Again, <leader>X
to close all tabs. Buffers which were already open won’t get closed, others will.
Another plugin which I may recommend is VCSCommand.