Question

I'm using the Fugitive plugin.

It has a command(?) Git! which executes a command and opens the result in a new buffer.

Example:

:Git! diff --cached

I have a function which calls this, and does some other things after that.

And I have this command declaration:

command! Hello execute ":Git! diff"

If I run :Hello from within vim, it works as it should. But when I run vim -c Hello, it throws this error:

Not an editor command :Git! diff

How can I do this?

(PS: How can I make this error message to stay until I press ? It appears for about a second and disappears.)

Was it helpful?

Solution

The reason is that Fugitive only defines its commands for buffers whose files are under Git version control. Precisely, the code in plugin/fugitive.vim only sets up autocmds that detect files under Git control, and only then defines buffer-local commands.

So at least you need to pass a Git-controlled file to your Vim invocation. If that still doesn't work, try explicitly triggering the detection via

:doautocmd User Fugitive
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top