这两个plugin在 www.vim.org 是排名前两位的(by rating),但是所谓鱼与熊掌不可兼得,minibufexpl与taglist合用时还是存在一点小问题。
在切换buffer时,如果之前焦点定位于taglist的窗口中,minibufexpl会毫不客气地在taglist的窗口中载入文件。为了解决这一点瑕疵,我对minibufexpl做了一点小修正。
请用以下代码替换原函数MBESelectBuffer()
"
MBENeedNextWindow - From the MBE window, test window under the cursor {{{
"
" If we are in our explorer, then we attempt to open the buffer under the
" cursor in the previous window.
"
function ! < SID > MBENeedNextWindow()
if bufname( ' % ' ) == ' -MiniBufExplorer- ' ||
bufname( ' % ' ) == ' __Tag_List__ ' ||
(g:miniBufExplModSelTarget == 1 && getbufvar(bufnr( ' % ' ), ' &modifiable ' ) == 0 )
return 1
else
return 0
endif
endfunction
" }}}
" MBESelectBuffer - From the MBE window, open buffer under the cursor {{{
"
" If we are in our explorer, then we attempt to open the buffer under the
" cursor in the previous window.
"
function ! < SID > MBESelectBuffer()
call < SID > DEBUG( ' =========================== ' , 10 )
call < SID > DEBUG( ' Entering MBESelectBuffer() ' , 10 )
call < SID > DEBUG( ' =========================== ' , 10 )
" Make sure we are in our window
if bufname( ' % ' ) != ' -MiniBufExplorer- '
call < SID > DEBUG( ' MBESelectBuffer called in invalid window ' , 1 )
return
endif
let l:save_rep = & report
let l:save_sc = & showcmd
let & report = 10000
set noshowcmd
let l:bufnr = < SID > GetSelectedBuffer()
let l:resize = 0
if (l:bufnr != - 1 ) " If the buffer exists.
let l:saveAutoUpdate = g:miniBufExplorerAutoUpdate
let g:miniBufExplorerAutoUpdate = 0
" Switch to the previous window
wincmd p
let curbufname = bufname( ' % ' )
" If we are in the buffer explorer or in a nonmodifiable buffer with
" g:miniBufExplModSelTarget set then try another window (a few times)
while < SID > MBENeedNextWindow()
wincmd w
if bufname( ' % ' ) == curbufname
break
endif
endwhile
" The following handles the case where -MiniBufExplorer-
" is the only window left. We need to resize so we don't
" end up with a 1 or two line buffer.
if bufname( ' % ' ) == ' -MiniBufExplorer- '
let l:resize = 1
endif
exec( ' b! ' .l:bufnr)
if (l:resize)
resize
endif
let g:miniBufExplorerAutoUpdate = l:saveAutoUpdate
call < SID > AutoUpdate( - 1 )
endif
let & report = l:save_rep
let & showcmd = l:save_sc
call < SID > DEBUG( ' =========================== ' , 10 )
call < SID > DEBUG( ' Completed MBESelectBuffer() ' , 10 )
call < SID > DEBUG( ' =========================== ' , 10 )
endfunction
"
" If we are in our explorer, then we attempt to open the buffer under the
" cursor in the previous window.
"
function ! < SID > MBENeedNextWindow()
if bufname( ' % ' ) == ' -MiniBufExplorer- ' ||
bufname( ' % ' ) == ' __Tag_List__ ' ||
(g:miniBufExplModSelTarget == 1 && getbufvar(bufnr( ' % ' ), ' &modifiable ' ) == 0 )
return 1
else
return 0
endif
endfunction
" }}}
" MBESelectBuffer - From the MBE window, open buffer under the cursor {{{
"
" If we are in our explorer, then we attempt to open the buffer under the
" cursor in the previous window.
"
function ! < SID > MBESelectBuffer()
call < SID > DEBUG( ' =========================== ' , 10 )
call < SID > DEBUG( ' Entering MBESelectBuffer() ' , 10 )
call < SID > DEBUG( ' =========================== ' , 10 )
" Make sure we are in our window
if bufname( ' % ' ) != ' -MiniBufExplorer- '
call < SID > DEBUG( ' MBESelectBuffer called in invalid window ' , 1 )
return
endif
let l:save_rep = & report
let l:save_sc = & showcmd
let & report = 10000
set noshowcmd
let l:bufnr = < SID > GetSelectedBuffer()
let l:resize = 0
if (l:bufnr != - 1 ) " If the buffer exists.
let l:saveAutoUpdate = g:miniBufExplorerAutoUpdate
let g:miniBufExplorerAutoUpdate = 0
" Switch to the previous window
wincmd p
let curbufname = bufname( ' % ' )
" If we are in the buffer explorer or in a nonmodifiable buffer with
" g:miniBufExplModSelTarget set then try another window (a few times)
while < SID > MBENeedNextWindow()
wincmd w
if bufname( ' % ' ) == curbufname
break
endif
endwhile
" The following handles the case where -MiniBufExplorer-
" is the only window left. We need to resize so we don't
" end up with a 1 or two line buffer.
if bufname( ' % ' ) == ' -MiniBufExplorer- '
let l:resize = 1
endif
exec( ' b! ' .l:bufnr)
if (l:resize)
resize
endif
let g:miniBufExplorerAutoUpdate = l:saveAutoUpdate
call < SID > AutoUpdate( - 1 )
endif
let & report = l:save_rep
let & showcmd = l:save_sc
call < SID > DEBUG( ' =========================== ' , 10 )
call < SID > DEBUG( ' Completed MBESelectBuffer() ' , 10 )
call < SID > DEBUG( ' =========================== ' , 10 )
endfunction