Starting vim-fugitive from command line
Asked Answered
J

5

9

I really like Fugitive (VIM git wrapper plugin) However I would like to create a script that starts vim and then runs

:Gstatus 

immediately. However when I try

vim -c Gstatus

I get an error stating that Gstatus is not an editor command

Jacobo answered 4/2, 2013 at 8:8 Comment(2)
At that point in your session, the fugitive plugin is probably not loaded or unable to work its magic. Can you do :GStatus right after you started Vim without any file?Backache
It seems fugative doesn't work unless there is a file loaded which is part of a git repository. The current directory satisfies that condition so starting gvim with the current directory as the current file works. See My answer below.Jacobo
J
6

vim +Gstatus +only works. I have it aliased to vimg

Jeer answered 18/3, 2020 at 16:3 Comment(2)
This is perfect, though +Gstatus is now deprecated in favor of +GitDiscomfiture
+Gstatus is deprecated. Instead do vim +Git +onlyAnnice
J
4

This works

gvim -c 'Gstatus | wincmd j | hide' .

makes the fugative window full size and hide the directory explorer buffer. Also with the directory buffer hidden when you quit the fugative buffer vim closes

Jacobo answered 4/2, 2013 at 8:27 Comment(3)
I prefer using vim -c Gstatus . since gives me a window to see diffs (pressing D on the cursor line) without closing the status window.Affectionate
The . directory trick doesn't work when NERDTree plugin is enabled, but . can be replaced by any other filename that doesn't exist.Affectionate
Just YFI for PowerShell/Windows users - . did NOT work for me as the file argument to Vim, so as Ricardo suggested, all I did was use temp as the file name. (Vim only creates the swap file for temp).Neuro
H
1

You can do this (assuming you are in the project root dir):

$ vim -c 'view .git/index'

It opens the git index in read-only mode (mimicking the essentials of the :Gstatus command)

Hobbyhorse answered 21/2, 2015 at 10:56 Comment(1)
You don't have the rich mappings available like with :Gstatus but it works for committing.Atlantis
L
1

As a slight improvement on bradgonesurfing's answer

vim -c 'Gstatus | wincmd o' .

This works even if you have splitbelow set

Ludwig answered 6/2, 2019 at 10:1 Comment(0)
A
0

Run vim +Git +only

I got here thanks to @jsm3031's answer, which nudged me in the right direction.

Annice answered 16/3, 2022 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.