Is there a way to list all open buffers in Vim? I’d like to view the full file path to every open buffer and save the list to an external file, or yank it for pasting into another text document.
Solution
This was a very hard contest! All three of the suggestions below worked well. I went with Luc Hermitte’s and added this to my .vimrc file:
noremap <silent> <leader>so :call writefile( map(filter(range(0,bufnr('$')), 'buflisted(v:val)'), 'fnamemodify(bufname(v:val), ":p")'), 'open_buffers.txt' )<CR>
So now typing ,so will save all the full path of all open buffers to the current directory in the open_buffers.txt file.
I’d have use the “simple”:
With:
range(0,bufnr('$'))to have a |List| of all possible buffer numbersfilter(possible_buffers, 'buflisted(v:val)')to restrict the list to the buffers that are actually listed — you may preferbufexist()that’ll also show the help buffers, etc.map(listed_buffer, 'nr_to_fullpath(v:val)')to transform all the buffer numbers into full pathnamesbufname()to transform a single buffer number into a (simplified) pathnamefnamemodify(pathname, ':p')to have a full absolute pathname from a relative pathname.Change
:echotocall writefile(pathname_list, 'filename'), and that’s all, or to:put=, etc.