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.
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.
Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.
I use a variant of your solution: :%bd<CR><C-O>:bd#<CR> This will delete all buffers, then use <C-O> to get restore the position in the current file, then :bd# to remove the unamed buffer. This closes all buffers and leaves you in the same location in the file.
Whenever you delete something from a file, vi keeps a copy in a temporary file called the general buffer. You can also delete or copy lines into temporary files called named buffers that will let you reuse those lines during your current vi work session.
I'd have use the "simple":
echo map(filter(range(0,bufnr('$')), 'buflisted(v:val)'), 'fnamemodify(bufname(v:val), ":p")')
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 prefer bufexist()
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 :echo
to call writefile(pathname_list, 'filename')
, and that's all, or to :put=
, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With