当只列出一个缓冲区时,vim:`:q`而不是`:b删除`
我想使用一个快捷方式(当只列出一个缓冲区时,vim:`:q`而不是`:b删除`,vim,Vim,我想使用一个快捷方式(,q)来删除我不需要的缓冲区,但当当前缓冲区是列出的唯一缓冲区时,我想使用相同的快捷方式来退出vim 我目前正在使用此功能: function! MyClose() " :q if at most one buffer is loaded " :bdelete otherwise let bufcount = len(filter(range(1,bufnr('$')), 'buflisted(v:val)==1')) if bufcount
,q
)来删除我不需要的缓冲区,但当当前缓冲区是列出的唯一缓冲区时,我想使用相同的快捷方式来退出vim
我目前正在使用此功能:
function! MyClose()
" :q if at most one buffer is loaded
" :bdelete otherwise
let bufcount = len(filter(range(1,bufnr('$')), 'buflisted(v:val)==1'))
if bufcount < 2
exe ":q"
else
exe ":bdelete"
endif
endfunction
函数!MyClose()
“:q如果最多加载一个缓冲区
“:b否则删除
设bufcount=len(过滤器(范围(1,bufnr(“$”),'buflisted(v:val)==1'))
如果bufcount<2
exe“:q”
其他的
exe“:b删除”
恩迪夫
端功能
然后
nnoremap <leader>q :call MyClose()<cr>
nnoremap q:callmyclose()
但我觉得我做得不对
- 有没有更好的方法来计算列出的缓冲区
- 有没有更好的方法来实现此功能
- 你是对的,你可以使用
:help选项卡pagebuflist
要获取所有现有缓冲区的列表,请执行以下操作
tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
在这种情况下,您只需要检查当前选项卡上的缓冲区,因为执行:q将关闭该选项卡