Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function! SortByCurrent(b1, b2)
- return a:b1['current'] == a:b2['current'] ? 0 : a:b1['current'] < a:b2['current'] ? 1 : -1
- endfunction
- function! SortByAlternate(b1, b2)
- return a:b1['alternate'] == a:b2['alternate'] ? 0 : a:b1['alternate'] < a:b2['alternate'] ? 1 : -1
- endfunction
- function! GetBufferList()
- redir =>bufliststr
- silent! ls
- redir END
- let bufferlist = map(map(split(bufliststr, '\n'), 'split(v:val, "\\s\\+")'),
- \ '{"number": v:val[0], "line": v:val[4], "name": v:val[2], "current": v:val[1] =~ "%", "alternate": v:val[1] =~ "#", "hidden": v:val[1] =~ "h"}')
- let current = sort(copy(bufferlist), 'SortByCurrent')[0]['number']
- let alternate = sort(copy(bufferlist), 'SortByAlternate')[0]['number']
- return {'list': bufferlist, 'current': current, 'alternate': alternate}
- endfunction
- echo GetBufferList()
Advertisement
Add Comment
Please, Sign In to add comment