Answers:
您可以<C-a>用来完成所有比赛。因此,如果您键入:bd *.xml然后单击<C-a>,vim将完成命令:bd file1.xml file2.xml file3.xml。
您也可以替代使用:
    :.,$-bd[elete]    " to delete buffers from the current one to last but one
    :%bd[elete]       " to delete all buffers
您可以使用它。
:exe 'bd '. join(filter(map(copy(range(1, bufnr('$'))), 'bufname(v:val)'), 'v:val =~ "\.xml$"'), ' ')
将其添加到命令中应该很容易。
function! s:BDExt(ext)
  let buffers = filter(range(1, bufnr('$')), 'buflisted(v:val) && bufname(v:val) =~ "\.'.a:ext.'$"')
  if empty(buffers) |throw "no *.".a:ext." buffer" | endif
  exe 'bd '.join(buffers, ' ')
endfunction
command! -nargs=1 BDExt :call s:BDExt(<f-args>)
glob()只会为您提供现有文件(在硬盘驱动器上),而不会打开缓冲区。
                    fnameescape()缓冲名称。
                    c:/Program files/foo.bar,甚至foo.bar.foo效果很好。fnameescape()如果我使用了缓冲区名称,则可能需要。但是我只检查缓冲区名称是否与给定表达式匹配:\.{ext}$-我将缓冲区编号提供给:bd`。我没有任何理由逃避正则表达式匹配。
                    试试下面的脚本。该示例用于“ txt”,根据需要将其更改,例如更改为“ xml”。修改后的缓冲区不会被删除。按\ bd删除缓冲区。
map <Leader>bd :bufdo call <SID>DeleteBufferByExtension("txt")
function!  <SID>DeleteBufferByExtension(strExt)
   if (matchstr(bufname("%"), ".".a:strExt."$") == ".".a:strExt )
      if (! &modified)
         bd
      endif
   endif
endfunction
[编辑] 不带:bufdo相同(按Luc Hermitte的要求,请参见下面的评论)
map <Leader>bd :call <SID>DeleteBufferByExtension("txt")
function!  <SID>DeleteBufferByExtension(strExt)
   let s:bufNr = bufnr("$")
   while s:bufNr > 0
       if buflisted(s:bufNr)
           if (matchstr(bufname(s:bufNr), ".".a:strExt."$") == ".".a:strExt )
              if getbufvar(s:bufNr, '&modified') == 0
                 execute "bd ".s:bufNr
              endif
           endif
       endif
       let s:bufNr = s:bufNr-1
   endwhile
endfunction
:bufdo因为它使当前窗口混乱。
                    我也一直都需要此功能。这是我在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>')
现在,我可以做:BW regex(例如:BW \.cpp$,擦除路径名称中与该模式匹配的所有匹配缓冲区。
如果要删除而不是擦除,当然可以替换exec 'bw ' . join(l:matchList, ' ')为exec 'bd ' . join(l:matchList, ' ')
:badd,:bdelete,:bufdo,:bn...)
                    
<tab>仅允许您循环显示匹配项,在命令行上输入一个条目<C-a>,一次添加所有匹配项。