如何在vim中编写“tabline”函数?
我希望Vim(而不是gVim)中的选项卡如下所示: 说明:如何在vim中编写“tabline”函数?,vim,Vim,我希望Vim(而不是gVim)中的选项卡如下所示: 说明: 选项卡的序号(1、2、3、4等) 文件名(无路径,无缩短路径) 如果打开了多个文件,请在选项卡中列出它们 如果存在重复的选项卡(因此在多个选项卡中打开同一文件),则应突出显示这些选项卡 如果修改了缓冲区,请在文件名末尾添加+ 有人能帮忙吗?我想在我的.vimrc中包含类似的内容: set tabline=%!MyTabLine() function! MyTabLine() ... endfunction :help setti
+
.vimrc
中包含类似的内容:
set tabline=%!MyTabLine()
function! MyTabLine()
...
endfunction
:help setting tabline
包含一个冗长的描述,包括一个模拟Vim默认tabline的示例函数。您可以将此作为起点。有关可用功能的完整列表,请参见:帮助功能
了解如何查找命令和导航内置的
:help
;它是全面的,并提供了许多提示。您学习Vim的速度不会像其他编辑器一样快,但如果您致力于持续学习,它将被证明是一个非常强大和高效的编辑器。我已经编写了我想要的tabline函数。行为几乎相同,除了:
+
符号set tabline=%!MyTabLine() " custom tab pages line
function! MyTabLine()
let s = ''
" loop through each tab page
for i in range(tabpagenr('$'))
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#' " WildMenu
else
let s .= '%#Title#'
endif
" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T '
" set page number string
let s .= i + 1 . ''
" get buffer names and statuses
let n = '' " temp str for buf names
let m = 0 " &modified counter
let buflist = tabpagebuflist(i + 1)
" loop through each buffer in a tab
for b in buflist
if getbufvar(b, "&buftype") == 'help'
" let n .= '[H]' . fnamemodify(bufname(b), ':t:s/.txt$//')
elseif getbufvar(b, "&buftype") == 'quickfix'
" let n .= '[Q]'
elseif getbufvar(b, "&modifiable")
let n .= fnamemodify(bufname(b), ':t') . ', ' " pathshorten(bufname(b))
endif
if getbufvar(b, "&modified")
let m += 1
endif
endfor
" let n .= fnamemodify(bufname(buflist[tabpagewinnr(i + 1) - 1]), ':t')
let n = substitute(n, ', $', '', '')
" add modified label
if m > 0
let s .= '+'
" let s .= '[' . m . '+]'
endif
if i + 1 == tabpagenr()
let s .= ' %#TabLineSel#'
else
let s .= ' %#TabLine#'
endif
" add buffer names
if n == ''
let s.= '[New]'
else
let s .= n
endif
" switch to no underlining and add final space
let s .= ' '
endfor
let s .= '%#TabLineFill#%T'
" right-aligned close button
" if tabpagenr('$') > 1
" let s .= '%=%#TabLineFill#%999Xclose'
" endif
return s
endfunction
如果您不知道,现在有一个堆栈交换站点!你的问题可能会让你的运气更好。“我不想让一些神奇的插件帮我做这件事,但要放入.vimrc的实际代码”这是完全相同的事情。我知道,但在大多数情况下,插件包含太多的代码,无法找到我想要学习/使用的实际块)然后从
:help functions
,开始,如果有些东西不起作用,而你在文档中找不到解决方案,请尝试一下并寻求帮助。@Romaill,在阅读了:help functions
之后,似乎你的答案是我想要的,所以发表文章,我接受它)