maxschlepzig
maxschlepzig

Reputation: 39155

How to add git file status to vim's statusline?

I am using vim-fugitive and adding %{fugitive#statusline()} to the statusline nicely displays the current git branch.

But what about a git file status indicator (like in a git status output)?

For example when an opened file is untracked, staged, clean etc. the indicator would display it in the statusline via '[?]', '[M]', '[C]' or something like that.

How to add such a indicator?

Upvotes: 9

Views: 3766

Answers (2)

twe4ked
twe4ked

Reputation: 2902

This will show a + if the current file is modified:

system("[[ -n \"$(git status --porcelain " . shellescape(expand("%")) . ")\" ]] && echo -n +")

As a vim-powerline segment:

https://github.com/twe4ked/dotfiles/blob/bd0f98531d3467e041af1b8f17556e0052389735/vim/plugin_config/powerline.vim#L1

Upvotes: 2

ZyX
ZyX

Reputation: 53644

You can try out my aurum plugin, with it one-character status indicator is %{Powerline#Functions#aurum#GetStatus()}. But note that one of the goals of the aurum is to hide VCS differences behind a plugin interface, so there are six statuses: added, unknown, modified, removed, deleted, ignored, clean: all derived from mercurial; and there are no statuses like “modified in index” (it is just “modified”).

For all statuses except “clean” uppercased first letter is displayed, for “clean” nothing is displayed at all. Use aurum#status() if you want to change this, Powerline#Functions#aurum#GetStatus() is just a two-line wrapper for aurum#status() function for use in powerline, no need to create a wrapper for a wrapper if you want to change the behavior.

Upvotes: 2

Related Questions