tpope / vim-fugitive

fugitive.vim: A Git wrapper so awesome, it should be illegal
https://www.vim.org/scripts/script.php?script_id=2975
20.05k stars 1.01k forks source link

Incomplete support for the `:tab` command? #2051

Closed vais closed 2 years ago

vais commented 2 years ago

First of all, thank you so much for Fugitive!

I've been messing around with my workflow, and created a key mapping for myself to quickly open :Git status window in a new tab (so that I can work with my diffs at full width and height), and when :Git is dismissed with gq, I'm taken back to the tab I was on before, like nothing happened :)

nmap <silent> gs :tab Git<Bar>silent! tabmove -1<CR>

The tab manipulation at the end there is needed because by default when a tab is closed, Vim will take you to the next tab, but I want to return to the tab from which I originally launched :Git.

My first shot at making this mapping looked like this:

nmap <silent> gs :-tab Git<CR>

But :-tab doesn't seem to work "as advertised" with :Git - instead of opening the new tab before the current tab, it opens it after the current tab, basically as if it just ignores the -. (I tested that e.g. :-tab split does indeed work as shown in Vim docs). Is there a reason for this not working with the :Git command? In fact, all flavors of :tab below seem to be ignored when used with :Git as well.

From the docs:

:[count]tab {cmd}                   *:tab*
        Execute {cmd} and when it opens a new window open a new tab
        page instead.  Doesn't work for |:diffsplit|, |:diffpatch|,
        |:execute| and |:normal|.
        If [count] is given the new tab page appears after the tab
        page [count] otherwise the new tab page will appear after the
        current one.
        Examples: >
            :tab split      " opens current buffer in new tab page
            :tab help gt    " opens tab page with help for "gt"
            :.tab help gt   " as above
            :+tab help      " opens tab page with help after the next
                    " tab page
            :-tab help      " opens tab page with help before the
                    " current one
            :0tab help      " opens tab page with help before the
                    " first one
            :$tab help      " opens tab page with help after the last
                    " one
tpope commented 2 years ago

This is a limitation of custom commands. Vim only provides tab in <mods>, omitting any count.

vais commented 2 years ago

Ah, makes sense! Thank you @tpope for the quick reply!