English 中文(简体)
Vim: Wiping Out Buffers 编辑
原标题:Vim: Wiping Out Buffers Editing Nonexistent Files

通常在Vim编辑时,我最后恢复Vim会议,会议提到已经移动的名录中的一些档案。 问题发生在我使用<代码>后:n打开新目录中的所有档案。 现在,当我使用<代码>:b <buffer-name>,改用新的名录中的某个特定档案进行缓冲编辑时,有含糊不清之处:在档案中,有两种缓冲器,名称相同,其中一个文档不存在。 因此,Im被迫使用<代码>:ls,人工检索未经编辑的缓冲指数,并打电话:bw。 是否有某种简单的指挥系统,将自动冲淡对我没有档案的缓冲?

此外,在人工冲销冒犯的缓冲器后,在连续的缓冲器之间出现 abrupt断,使使用<代码>的缓冲器:<n>b的转换更为困难。 是否有指挥部将我缓冲地带重新编号,以便一套指数是一些毗连范围?

Thanks for your help!

最佳回答

Try the following command:

function s:WipeBuffersWithoutFiles()
    let bufs=filter(range(1, bufnr( $ )),  bufexists(v:val) &&  .
                                           empty(getbufvar(v:val, "&buftype")) &&  .
                                           !filereadable(bufname(v:val)) )
    if !empty(bufs)
        execute  bwipeout  join(bufs)
    endif
endfunction
command BWnex call s:WipeBuffersWithoutFiles()

使用:

:BWnex<CR>

  • filter(range(1, bufnr( $ )), bufexists(v:val) ) will present you a list of all buffers (buffer numbers) that vim currently has.
  • empty(getbufvar(v:val, &buftype )) checks whether buffer actually should have a file. There are some plugins opening buffers that are never supposed to be represented in filesystem: for example, buffer with a list of currently opened buffers emitted by plugins such as minibufexplorer. These buffers always have &buftype set to something like nofile, normal buffers have empty buftype.
问题回答

Aren t buffers supposed to be unique?

在指挥顺序之后:

:e .bashrc
:e .profile
:e .bashrc
:e .profile
:e .bashrc
:e .profile
:e .bashrc
:e .profile
:e .bashrc

如<代码>:buffers或:ls:.bashrc所示,我仍然只有两个缓冲器。 即使我使用多个窗口和表格。

Are you confusing "buffers" with "windows"?

Both of my suggestions are workarounds, but I thought worth mentioning. One way is to :ls then grab with the mouse, paste into a scratch buffer and then launch from command line.

当我的缓冲区被关闭时,我通常关闭窗口。 然后,我从我的肩上指挥,发射所有从我的源头控制中查取的档案——90%的时间是我感兴趣的档案。

I m 通常在cy子上。 run

gvim `p4list` `svnopened`

<代码>p4listsvn opened 如下:

function p4list() {
  export tempscript=`mktemp`
  echo "#!bash" > $tempscript
  p4 opened $@ | sed -e  s/#.*//g  | sed -e  s/$/ \/g  | sed -e  1~300s/^/

p4 where /  >> $tempscript
  chmod +x $tempscript
  $tempscript | sed -e  s/.* //g  | sed -e  s/

//g | sed -e s////g rm $tempscript }

function svnopened() {
    svn st $@ | grep "^M" | sed -e  s/^.{8}// 
}




相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签