I took Luc Hermitte's helpful answer and improved it somewhat.
- It was returning unlisted (previously deleted) buffers, which isn't what I wanted. It now filters on
buflisted(v:val)
, rather than on !empty(v:val)
.
- I've added two commands:
Lssave
: saves the unsorted buffer list as-is
LSsave
: saves a sorted version of the buffer list
mkdir
the output file's path, in case it doesn't already exist.
function s:bufferList()
let l:bufferRange = range(1,bufnr('$'))
let l:bufferList = map(l:bufferRange, 'bufname(v:val)')
let l:bufferListListed = filter(l:bufferList, 'buflisted(v:val)')
return l:bufferListListed
endfunction
command Lssave
\ let s:bufferList = s:bufferList() |
\ call mkdir("/path/to", "p", 0740) |
\ call writefile(s:bufferList, "/path/to/filename.txt")
command LSsave
\ let s:bufferList = s:bufferList() |
\ let s:bufferListSorted = sort(s:bufferList) |
\ call mkdir("/path/to", "p", 0740) |
\ call writefile(s:bufferListSorted, "/path/to/filename.txt")
I know that there is the viminfo file
Do you also know that there's:oldfiles
command? Doesn't it make the whole idea of having "an own file" useless?