I use undotree to visualize the changes available in my undofile. Is it possible to merge a branch of the undofile with the current version of the file I am working on?

I am looking for something similar to merging two versions of a file in git. Example undo tree shown by the undotree plugin


1 Answer 1


I would:

  1. Save the current version to disk
  2. Select the version from the undo tree
  3. Run the :Diff command

Remark: The :Diff command is not a standard Vim command but it is a common addition.

Here is the version of @romainl:

function! Diff(spec)
    vertical new
    setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
        let cmd = "++edit #"
    if len(a:spec)
        let cmd = "!git -C " .. shellescape(fnamemodify(finddir('.git', '.;'), ':p:h:h')) .. " show " .. a:spec .. ":#"
    execute "read " .. cmd
    silent 0d_
    wincmd p

command! -nargs=? Diff call Diff(<q-args>)
  • @Matt is the solution addressing your problem. If so could you validate it using the v green button next to the arrow voting button. It allow the question to rest :-) Feb 26 at 5:25
  • 1
    I had hoped for a more efficient approach to this matter, but it seems that no alternative exists at the moment.
    – Matt
    Sep 13 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.