tags:

views:

204

answers:

2

for a tool i need to figure all vim buffers that are still listed (there are listed and unlisted buffers)

unfortunately vim.buffers contains all buffers and there doesnt seem to be an attribute to figure if a buffer is listed or unlisted

the vim command of what i want to do is

:buffers

unfortunately all thats possible with the vim python api is emulating

:buffers!

but without the metadata about listed/unlisted thats we need

+5  A: 

Here is how you can manage this using just Vim language.

function s:buffers_list()
    let result = []

    for buffer_number in range(1, bufnr('$'))
        if !buflisted(buffer_number)
            continue
        endif

        call add(result, buffer_number)
    endfor

    return result
endfunction
Mykola Golubyev
+1  A: 

Using Vim's python api:

listedBufs = []
for b in vim.buffers:
    listed = vim.eval('buflisted(bufnr("%s"))' % b.name)
    if int(listed) > 0:
        listedBufs.append(b)

or if you don't mind sacrificing some readability:

listedBufs = [b for b in vim.buffers
              if int(vim.eval('buflisted(bufnr("%s"))' % b.name)) > 0]
jamessan