简体   繁体   English

在gvim中自定义选项卡工具提示以显示缓冲区列表

[英]customizing tab tooltip in gvim to show buffer list

Currently running: 当前正在运行:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep  1 2012 18:08:47)
MacOS X (unix) version
Included patches: 1-646
Compiled by Bjorn Winckler <bjorn.winckler@gmail.com>

I have the following code in my .gvimrc which should display a list of all buffers as a tooltip. 我的.gvimrc中包含以下代码,该代码应显示所有缓冲区的列表作为工具提示。 However, it only shows the list of buffers that are visibly open in the current tab (split windows). 但是,它仅显示在当前选项卡(拆分窗口)中可见打开的缓冲区列表。 The :buffers command lists all the buffers properly. :buffers命令正确列出所有缓冲区。

Am I misunderstanding what this code is meant to do (I'm a newbie to Vim scripting; this code was borrowed from an open sourced configuration)? 我是否误解了这段代码的含义(我是Vim脚本的新手;该代码是从开源配置中借用的)?

"show tooltips on tabs
  set guitabtooltip=%{GuiTabToolTip()}

" set up tab tooltips with every buffer name
function! GuiTabToolTip()
  let tip = ''
  let bufnrlist = tabpagebuflist(v:lnum)

  for bufnr in bufnrlist
    " separate buffer entries
    if tip!=''
      let tip .= ' | '
    endif

    " Add name of buffer
    let name=bufname(bufnr)
    if name == ''
      " give a name to no name documents
      if getbufvar(bufnr,'&buftype')=='quickfix'
        let name = '[Quickfix List]'
      else
        let name = '[No Name]'
      endif
    endif
    let tip.=name

    " add modified/modifiable flags
    if getbufvar(bufnr, "&modified")
      let tip .= ' [+]'
    endif
    if getbufvar(bufnr, "&modifiable")==0
      let tip .= ' [-]'
    endif
  endfor

  return tip
endfunction

The source of the buffer is tabpagebuflist() , which, as :help tabpagebuflist() explains, is a list of buffer numbers associated with each window in the current tab page. 缓冲区的来源是tabpagebuflist() ,如:help tabpagebuflist() ,它是与当前选项卡页面中每个窗口关联的缓冲区编号的列表。

To get the list of all buffers, you'd have to use something like 要获取所有缓冲区的列表,您必须使用类似

filter(range(1, bufnr('$')), 'buflisted(v:val)')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM