Skip to content

Instantly share code, notes, and snippets.

@LemonBoy
Created September 23, 2017 11:44
Show Gist options
  • Save LemonBoy/c99217da1607e4a0ffba613caa315c68 to your computer and use it in GitHub Desktop.
Save LemonBoy/c99217da1607e4a0ffba613caa315c68 to your computer and use it in GitHub Desktop.
func! Format(_, what) abort
let flags = ' +'[a:what.changed]
\ . ' %'[a:what.bufnr == bufnr('')]
\ . ' #'[a:what.bufnr == bufnr('#')]
if empty(a:what.name)
let name = '[No Name]'
else
let name = fnamemodify(a:what.name, ':~:.')
endif
return printf(" %2d %s %s", a:what.bufnr, flags, name)
endfunc
func! DoList() abort
let buf_info = getbufinfo({ 'buflisted': 1, 'bufloaded': 1})
let by_ext = {}
let res = ''
" divide in buckets
for buf in buf_info
let ext = fnamemodify(buf.name, ':e')
if empty(ext)
let ext = get(buf.variables, 'current_syntax', 'xxx')
endif
let by_ext[ext] = add(get(by_ext, ext, []), buf)
endfor
for key in sort(keys(by_ext))
let res .= '[' . key . ']:' . "\n"
let res .= join(map(by_ext[key], function('Format')), "\n") . "\n"
endfor
" remove the last '\n'
let res = res[:-2]
echo res
endfunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment