Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

vim

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?

like image 853
maxschlepzig Avatar asked Sep 22 '12 14:09

maxschlepzig


2 Answers

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.

like image 151
ZyX Avatar answered Sep 28 '22 16:09

ZyX


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

like image 28
twe4ked Avatar answered Sep 28 '22 18:09

twe4ked