Created
November 8, 2013 12:32
-
-
Save rgs/7370406 to your computer and use it in GitHub Desktop.
A vim status line item to display git branch name and status of the currently edited file. To be put in the ~/.vimrc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" returns a string <branch/XX> where XX corresponds to the git status | |
" (for example "<master/ M>") | |
function CurrentGitStatus() | |
let gitoutput = split(system('git status --porcelain -b '.shellescape(expand('%')).' 2>/dev/null'),'\n') | |
if len(gitoutput) > 0 | |
let b:gitstatus = strpart(get(gitoutput,0,''),3) . '/' . strpart(get(gitoutput,1,' '),0,2) | |
else | |
let b:gitstatus = '' | |
endif | |
endfunc | |
autocmd BufEnter,BufWritePost * call CurrentGitStatus() | |
" example of use in the status line: | |
set stl=%f\ %(<%{b:gitstatus}>%) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there,
i found your code snippet pretty useful but also, that i wont work properly for vim working directories outside of a git repository.
Example:
vim outside/git_repo/some.file
... won't display the branch even thou it's a repository.
I made two small commits to fix this.