Lightline.vim: Support for any of the hunk plugins (signify, git-gutter et al)

Created on 25 Mar 2015  路  5Comments  路  Source: itchyny/lightline.vim

As stated in the title already: will there be any support for hunk plugins like signify or git-gutter? That's the only thing missing which keeps me away from lightline. Unfortunately I'm not able to configure lightline in a way that would satisfy my (simple) needs.

configuration

Most helpful comment

Note that count is an exceptional variable name in Vim script. See :h l:.

All 5 comments

I've never used those two plugins. Please refer to the helps of those plugins. I do not know what gutter is but the function GitGutterGetHunkSummary might help you.

Even though closed I want to contribute my solution that I found together with the creator of vim-signify (mhinz).

He suggested to write a wrapper function around a signify function:

function! s:sy_stats_wrapper()
  let symbols = ['+', '-', '~']
  let [added, modified, removed] = sy#repo#get_stats()
  let stats = [added, removed, modified]  " reorder
  let hunkline = ''

  for i in range(3)
    if stats[i] > 0
      let hunkline .= printf('%s%s ', symbols[i], stats[i])
    endif
  endfor

  if !empty(hunkline)
    let hunkline = printf(' [%s]', hunkline[:-2])
  endif

  return hunkline
endfunction

That can be used then to be implemented in the statusline (be it your own statusline or from a statusline plugin like lightline) ...

I hope this is useful to someone.

Here's a similar function that includes the name of the VCS and reuses the same characters signify uses for the gutter.

It's also more compact, you can add spaces around the strings if it feels too cramped.

function! LightlineSignify()
let [added, modified, removed] = sy#repo#get_stats()
let l:sy = ''
for [flag, count] in [
    \   [g:signify_sign_add, added],
    \   [g:signify_sign_delete, removed],
    \   [g:signify_sign_change, modified]
    \ ]
    if count > 0
        let l:sy .= printf('%s%d', flag, count)
    endif
endfor
if !empty(l:sy)
    let l:sy = printf('[%s]', l:sy)
    let l:sy_vcs = get(b:sy, 'updated_by', '???')
    return printf('%s%s', l:sy_vcs, l:sy)
else
    return ''
endif
endfunction

I had some problems getting @somini's function to work. Specifically, I did not have the global Signify variables defined, and I wasn't able to modify count.

Here's a slightly improved version of the function:

function! LightlineSignify()
let [added, modified, removed] = sy#repo#get_stats()
let l:sy = ''
for [flag, flagcount] in [
    \   [exists("g:signify_sign_add")?g:signify_sign_add:'+', added],
    \   [exists("g:signify_sign_delete")?g:signify_sign_delete:'-', removed],
    \   [exists("g:signify_sign_change")?g:signify_sign_change:'!', modified]
    \ ]
    if flagcount> 0
        let l:sy .= printf('%s%d', flag, flagcount)
    endif
endfor
if !empty(l:sy)
    let l:sy = printf('[%s]', l:sy)
    let l:sy_vcs = get(b:sy, 'updated_by', '???')
    return printf('%s%s', l:sy_vcs, l:sy)
else
    return ''
endif
endfunction

Note that count is an exceptional variable name in Vim script. See :h l:.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Blosberg picture Blosberg  路  4Comments

kbc8090 picture kbc8090  路  3Comments

rotsix picture rotsix  路  4Comments

mrbig033 picture mrbig033  路  4Comments

ahmedelgabri picture ahmedelgabri  路  3Comments