2010-08-17 20 views
1

我经常想要擦除加载了给定扩展名的所有缓冲区(通常是由补丁生成的.rej文件)。只是在做:bw [!] * .rej会抱怨如果有多个匹配。有没有人有任何好的提示?目前我要么重复使用:bw * .rej + tab-complete,或者如果有很多缓冲区,请使用:ls和:bw一组数字的缓冲区。如何获得:bwipe * .ext擦除匹配vim中的通配符的所有人

+0

听起来像是你可能需要编写(或发现)一个插件来做到这一点。 :bwipe只会像你所经历的那样需要一个'bufname'。 – cam 2010-08-17 21:59:19

回答

1

在vim中泛化有点困难(除了文件系统上的文件)。因此,最好的方法似乎是将通配符转换为正则表达式,然后检查缓冲区列表中的每个缓冲区以查看它是否匹配。事情是这样的:

" A command to make invocation easier 
command! -complete=buffer -nargs=+ BWipe call BWipe(<f-args>) 

function! BWipe(...) 
    let bufnames = [] 
    " Get a list of all the buffers 
    for bufnumber in range(0, bufnr('$')) 
     if buflisted(bufnumber) 
      call add(bufnames, bufname(bufnumber)) 
     endif 
    endfor 
    for argument in a:000 
     " Escape any backslashes, dots or spaces in the argument 
     let this_argument = escape(argument, '\ .') 
     " Turn * into .* for a regular expression match 
     let this_argument = substitute(this_argument, '\*', '.*', '') 

     " Iterate through the buffers 
     for buffername in bufnames 
      " If they match the provided regex and the buffer still exists 
      " delete the buffer 
      if match(buffername, this_argument) != -1 && bufexists(buffername) 
       exe 'bwipe' buffername 
      endif 
     endfor 
    endfor 
endfunction 

它可以作为:

:BWipe *.rej 

或:

:BWipe *.c *.h 
+0

这非常有帮助,谢谢! – Luke 2010-08-20 16:48:01

0

顺便说一句,我结束了一个非常低技术的解决方案去(我个人喜欢尽可能少的修改vim以便我在任何机器上都可以):

我添加了一个映射:

:地图<比照>:BW *名为.rej

后来我反复按 <比照> <标签> <CR>

+0

听起来合理。通过在可用的任意版本控制下保留整个'.vim'(或Windows上的vimfiles)和vimrc,我可以绕过“在任何机器的家中”问题。这样,我所做的任何更改都会被推送到我正在使用的任何一台机器(或USB存储棒)。 – DrAl 2011-01-11 18:00:48

相关问题