Ja też miałem potrzebę tej funkcji przez cały czas. To jest rozwiązanie, które mam w moim vimrc.
function! GetBufferList()
return filter(range(1,bufnr('$')), 'buflisted(v:val)')
endfunction
function! GetMatchingBuffers(pattern)
return filter(GetBufferList(), 'bufname(v:val) =~ a:pattern')
endfunction
function! WipeMatchingBuffers(pattern)
let l:matchList = GetMatchingBuffers(a:pattern)
let l:count = len(l:matchList)
if l:count < 1
echo 'No buffers found matching pattern ' . a:pattern
return
endif
if l:count == 1
let l:suffix = ''
else
let l:suffix = 's'
endif
exec 'bw ' . join(l:matchList, ' ')
echo 'Wiped ' . l:count . ' buffer' . l:suffix . '.'
endfunction
command! -nargs=1 BW call WipeMatchingBuffers('<args>')
Teraz mogę tylko zrobić :BW regex
(np :BW \.cpp$
i wytrzeć wszystkie pasujące bufory, które mają zgodne ze wzorcem w ich ścieżki.
Jeśli chcesz usunąć zamiast wycierać, można oczywiście zastąpić exec 'bw ' . join(l:matchList, ' ')
z exec 'bd ' . join(l:matchList, ' ')
Awesome! Bez wtyczek :) Dziękuję. – Salil
tak niesamowite. dzięki! – tester
lub '' zamiast '' działa również. –
Florian