VIM 自定義TabLine禁籤

環境:macOS1015.3 

vim 的標籤頁的切換可以用[n]gt命令來實現,n是第幾個標籤,但有時需要數一下才知是第幾個,有點麻煩,看了一下vim的幫助,可以自定義標籤,加個序號進去。 並改了一下樣式(在顏色方案裏改TabLine TabLineFill TabLineSel顏色),加點裝飾,先看效果:

修改方式:

在.vimrc裏添加下面 vimscript

" 自定定義tabpage的label (參考:help tabpage)
set tabline=%!MyTabLine()
function MyTabLine()
    let s = ''
    for i in range(tabpagenr('$'))
        " select the highlighting
        if i + 1 == tabpagenr()
            let s .= '%#TabLineSel#'
        else
            let s .= '%#TabLine#'
        endif

        " set the tab page number (for mouse clicks)
        let s .= '%' . (i + 1) . 'T'

        " the label is made by MyTabLabel()
        let s .= '%{MyTabLabel(' . (i + 1) . ')}'
    endfor

    " after the last tab fill with TabLineFill and reset tab page nr
    let s .= '%#TabLineFill#%T'

    " right-align the label to close the current tab page
    if tabpagenr('$') > 1
        let s .= '%=%#TabLine#%999XX'
    endif

    return s
endfunction
function MyTabLabel(n)
    let buflist = tabpagebuflist(a:n)
    let winnr = tabpagewinnr(a:n)

    " Add '+' if one of the buffers in the tab page is modified
    let label = ''
    for bufnr in buflist
        if getbufvar(bufnr, "&modified")
            let label = '+'
            break
        endif
    endfor 

    "添加tabpage序號,方便ngt切換
    let bg=['☰','☱','☲','☳','☴','☵','☶','☷'][(a:n-1)%8]
    return '  🐶['.a:n.label.']'.pathshorten(bufname(buflist[winnr - 1])).' '
endfunction

 

 

參考:原創 在線vim配色加term與gui統一顏色調整python腳本

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章