dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

vim-status.vim (2304B)


      1 set laststatus=2
      2 
      3 if !exists('g:status_color_dark')
      4     \ | let g:status_color_dark = 'ctermfg=6 ctermbg=5'
      5     \ | endif
      6 if !exists('g:status_color_light')
      7     \ | let g:status_color_light = 'ctermfg=5 ctermbg=6'
      8     \ | endif
      9 if !exists('g:status_color_git')
     10     \ | let g:status_color_git = 'ctermfg=3 ctermbg=5'
     11     \ | endif
     12 
     13 function! SetStatusColorscheme()
     14     exec 'hi User1 ' . g:status_color_dark
     15     exec 'hi User2 ' . g:status_color_light
     16     exec 'hi User3 ' . g:status_color_git
     17 endfunc
     18 
     19 function! SetGitStatusLine()
     20     let g:status_git_status = ""
     21     if expand("%") == ""
     22         return
     23     endif
     24     let isgit = system("git -C '" . expand("%:h")
     25         \ . "' rev-parse")[:-2]
     26     let istracked = system("git -C '" . expand("%:h")
     27         \ . "' ls-files " . expand("%:t"))[:-2]
     28 
     29     if isgit == "" && istracked == expand("%:t")
     30         let stats = system("git -C '" . expand("%:h")
     31             \ . "' diff --numstat -- " . expand("%:t")
     32             \ . " | awk '{printf \"+%d -%d\", $1, $2}'")
     33         let branch = system("git -C '" . expand("%:h")
     34             \ . "' branch | grep \\* | awk '{printf \"%s\", $2}'")
     35         let g:status_git_status = ((stats == "" ? "+0 -0" : stats)
     36             \ . "  "  . branch . "  ")
     37     endif
     38 endfunction
     39 
     40 if has('statusline')
     41     call SetStatusColorscheme()
     42     call SetGitStatusLine()
     43 
     44     function! SetStatusLineStyle()
     45         let &stl  = ""
     46         let &stl .= "%1* %n"
     47         let &stl .= " %2* "
     48         let &stl .= "%<%F"
     49         let &stl .= "%( [%R%M]%)"
     50         let &stl .= " %1*%1* "
     51         let &stl .= "%3*%{g:status_git_status}"
     52         let &stl .= "%= "
     53         let &stl .= "%1*  "
     54         let &stl .= "%1*%{&fileformat}"
     55         let &stl .= "%1*  "
     56         let &stl .= "%1*%(%{(&fenc!=''?&fenc:&enc)}%)"
     57         let &stl .= "%1*  "
     58         let &stl .= "%1*%(%{&filetype}%)"
     59         let &stl .= " %1*%2* "
     60         let &stl .= "%2*%4.l/%-4.L\ "
     61         let &stl .= "(%-3.p%%)"
     62         let &stl .= "%2* | %-4.c"
     63         let &stl .= "%2*[0x%04B] "
     64     endfunc
     65 
     66     au BufWritePost         * call SetGitStatusLine()
     67     au ColorScheme          * call SetStatusColorscheme()
     68     au ColorScheme,VimEnter * call SetStatusLineStyle()
     69     nmap _ds :call SetStatusLineStyle()<CR>
     70     call SetStatusLineStyle()
     71 endif