I need to repeat the following workflow multiple times:

  • I have a repository with two branches
  • I need to work simultaneously with two revisions of the same file, each revision belonging to one of the branches:
    • I need to be able to see the differences by using diff mode
    • I need to be able to make changes in each version

I'd like to know what approach should I use and what eventually useful vim plugins could help me. I did not mention the version control on purpose because I'd like some version control agnostic suggestions: I need to do this in repositories handled by misc vcs tools - at least git, fossil and darcs.

Edit: adding what I have in mind now (and what I don't really like, hence looking for better suggestions)

I could make two clones of the repository, check out needed revision from first branch in one, check out other needed revision from second branch in another repository. Then just use

vimdiff /full/path/to/file/in/first/repo /full/path/to/file/in/second/repo

But to me this looks like too much being done outside of vim

Ideally I'd probably like a vim plugin that understands many different version control repository formats and can do this workflow for me behind the curtain, so I only pass revision1, revision2, filename to it (inside vim) and I can get a vimdiff window with two versions of the same file so I could work on them.

  • @HerbWolfe not sure it's a duplicate, I'll edit my question to include my thoughts on how I would do it (indeed, by using vim just as a diff tool, totally out of version control context), but intuitively I don't like my approach, hence I'm trying to reach out for better suggestions that could minimize the amount of work I would need to do outside vim. Dec 2, 2018 at 7:25
  • 1
    Sounds like you're primarily looking for a version control abstraction layer. While there might be such a thing it almost certainly is not related to Vim.
    – B Layer
    Dec 2, 2018 at 9:08
  • If you are using git, you can check out two different branches using e.g. worktrees. Then you can simultaneously edit the same file in different branches and can then use Vimdiff to view differences of files Dec 3, 2018 at 7:58
  • I think a bash script as a wrapper would do. It could execute the pre and post vcs commands and call vimdiff in between. A nice mapping I often need for vimdiff is nnoremap <F10> :qa!<CR> (quit, no matter if files are changed)
    – Rolf
    Dec 11, 2018 at 8:11


Browse other questions tagged or ask your own question.