是否可以在 vim 中更改每个文件类型的选项卡标题颜色? [英] Is it possible to change tab header color each filetype in vim?
问题描述
如果我打开 .js、.html、.rb 和其他文件类型,是否可以更改每种文件类型的标签颜色?Tab 表示 vim 的 tab 不像空格.
If I'm opening .js, .html, .rb and other filetype, is it possible to change tab color each filetype? Tab means vim's tab not like space.
推荐答案
使用格式 %#String#
will color with the string hightlight :
- set tabline=%#String#\ toto
Use the format %#String#
will color with the string hightlight :
- set tabline=%#String#\ toto
一个放在 vimrc 中的脚本:
A script to put in your vimrc:
function! TabTest()
let res = ''
for i in range(tabpagenr('$'))
let i += 1
" Get open buffer
let i_window = tabpagewinnr(i)
let l_buffer = tabpagebuflist(i)
let i_buffer = l_buffer[i_window - 1]
" Get type
let s_type = getbufvar(i_buffer, '&filetype')
" Set color according to filetype
let s_color = ''
if i == tabpagenr()
let res .= '%#TabLine#'
elseif 'javascript' == s_type
let res .= '%#String#'
elseif 'html' == s_type
let res .= '%#Comment#'
else
let res .= '%#Normal#'
endif
" set the tab page number (for mouse clicks)
let res .= '%' . (i + 1) . 'T'
" Set label text
let s_buffer = bufname(i_buffer)
try
let s_file = split(s_buffer, '/')[-1]
catch
let s_file = '[No Name]'
endtry
let res .= ' ' . s_file
endfor
return res
endfunction
set tabline=%!TabTest()
当您根据文件类型要求颜色突出显示时,您必须获取缓冲区的文件类型:
- let s_type = getbufvar(i_buffer, '&filetype')
As you are asking for an color hightlight according to the filetype, you must get the filetype of a buffer:
- let s_type = getbufvar(i_buffer, '&filetype')
为此,您必须在选项卡中获取活动缓冲区的缓冲区编号:
- let i_window = tabpagewinnr(i)
- let l_buffer = tabpagebuflist(i)
- 让 i_buffer = l_buffer[i_window - 1]
For this you must get the buffer number of the activer buffer in the tab:
- let i_window = tabpagewinnr(i)
- let l_buffer = tabpagebuflist(i)
- let i_buffer = l_buffer[i_window - 1]
那么您必须明智地使用 if 区分文件类型.所以你肯定想在一个函数中隐藏所有这些:set tabline=%!TabTest()
Then you must wisely distinguish accroding to the filetype with a if. So you definitely want to hide all this in a function:
set tabline=%!TabTest()
更多:h 标签行
h 状态行
这篇关于是否可以在 vim 中更改每个文件类型的选项卡标题颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!