4

How can I make Neovim automatically return to the tabpage that was active before running :Git diff %?

Before I commit my work in git, I often run :Git diff to review changes (the :Git command is supplied by fugitive). The :Git diff command runs in a new instance of Neovim's terminal, which seems to open in a new tabpage of its own. I press q to abort the process, and the new tabpage disappears. Neovim then activates the next available tabpage, instead of returning to the tabpage that was active before I ran :Git diff.

For example, suppose that I've got Neovim running with three tabpages. If I run 1gt to activate the first tabpage, then after running :Git diff I'll finish up on the second tabpage (I'll then press gT to go back to the tab I was working on). If I run 2gt to activate the second tabpage, then after running :Git diff I'll finish up on the third tabpage (again, gT gets me back to where I was). If I run 3gt, then I can run :Git diff and remain on the third tabpage, because it's the last one that's open.

I'd like to be able to run 1gt, then :Git diff, and to be automatically returned to the first tabpage when the terminal process exits. How can I make that happen?

  • 2
    I can't reproduce your problem here. I'm seeing that the git diff tab is created before the current active tab, which would make the "close-and-go-to-next" land on the good tab. Can this be the problem? – nobe4 Jan 20 '17 at 15:35
  • 2
    Also, from the fugitive code it would make sense for the tab to be created before the current one: github.com/tpope/vim-fugitive/blob/master/plugin/… – nobe4 Jan 20 '17 at 15:45
  • I typically use :Gstatus. If i am concerned with the exact nature of my commit I use the cvc command which does :Gcommit --verbose which gives the diff below the message. – Peter Rincker Jan 20 '17 at 22:33
3

This patch on fugitive fixes this issue (and here's the PR). It looks like I was running an old version of fugitive. Upgrading to the latest fugitive fixed this issue for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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