1

I am using the vim-fugitive plugin and I encounter a strange behaviour. I don't know if it's really related to the plugin or not.

I am trying to open the Gstatus page in a new tab. So I am creating a new tab and call Gstatus on the new tab :

:tabnew | Gstatus

And I get the following error :

E492: Not an editor command: Gstatus

Do you know what might cause the issue and how to fix it ? I can create a function to achieve this behavior, but I wanted to keep a mapping like the one I currently use :

nnoremap <Leader>gs tabnew | Gstatus<CR>

Edit :

  • When starting vim inside a git directory without a file, the Gstatus works.
  • When creating a new tab and running Gstatus by hand, the command failed, even if the pwd command shows the good directory.
9
  • Well, it's probably because when you create a new tab, you are also in a new buffer ... and :Gstatus needs the current buffer to be under version control (git).
    – VanLaser
    Sep 8, 2015 at 11:07
  • I understand, but if I run the Gstatus command by hand after the newtab the command runs without problem
    – nobe4
    Sep 8, 2015 at 11:09
  • I just tested (with tabnew) and it doesn't. This is consistent with the docs :h fugitive-commands
    – VanLaser
    Sep 8, 2015 at 11:11
  • My bad, it doesn't. I must have tested with a file open. I edited my question
    – nobe4
    Sep 8, 2015 at 11:13
  • BTW, Gstatus should not work without a file, even if in the right folder. It's the first item on the FAQ: github.com/tpope/vim-fugitive
    – VanLaser
    Sep 8, 2015 at 11:20

3 Answers 3

7

Using <c-w>T to promote a window to a new tab.

nnoremap <Leader>gs :Gstatus<cr><c-w>T

For more help see :h CTRL-W_T

1
  • 6
    Or, purely in terms of commands, :Gstatus | wincmd T.
    – muru
    Sep 8, 2015 at 16:41
5

I'll just quote from the official plugin FAQ:

FAQ

Q: I installed the plugin and started Vim. Why don't any of the commands exist?

A: Fugitive cares about the current file, not the current working directory. Edit a file from the repository.

Q: I opened a new tab. Why don't any of the commands exist?

A: Fugitive cares about the current file, not the current working directory. Edit a file from the repository.

It doesn't matter if you are, or not, in a Git controlled folder. :Gstatus is a buffer-local command, it will only be available if the currently loaded buffer deals with a file which is under git revision control. Therefore, when you open a new tab, the current buffer is an empty one, and :Gstatus is not defined.

1

The question is old, but the answers are either not optimal or wrong.

The VIM command tabnew creates a new a buffer in a new tab. You should use only tab command, like so:

nnoremap <Leader>gs <CMD>tab Git<CR>

Good luck on your VIM journey.

1
  • 1
    Indeed, the :tab modifier will execute the command that follows in a new tab. For those who don't require a mapping, :Gstatus is now replaced by :Git or :G, so one could quickly type :tab G
    – husB
    Oct 3, 2022 at 9:05

Your Answer

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

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