I'm trying to get the list of absolute paths to my buffers, but cannot work out how to add the :p
to expand
as in expand("v:val:p")
into map.
let l:buffers = filter(range(1, bufnr('$')), 'buflisted(v:val)')
let l:buffiles = map(copy(l:buffers), 'expand(bufname(v:val).":p")')
The above does not work and append :p
to end of each filename loaded as buffer. .e.g.
['.vim/vimrc:p']
What's the right way to pass an expand modifier inside map or filter expression?
The right way is :h getbufinfo()
.
let l:files = map(getbufinfo({'buflisted': 1}), 'v:val.name')
Concerning arbitrary file name expansion, it is what :h fnamemodify()
is used for.
echo fnamemodify('filename.ext', ':p')
On the other hand, :h expand()
performs an expansion of :h cmdline-special
.