Created
August 14, 2014 17:04
-
-
Save kimat/ac3ae66986eb4298f3e5 to your computer and use it in GitHub Desktop.
vim-ctrlspace alternative tabline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g:ctrlspace_use_tabline=2 | |
let g:ctrlspace_unicode_font=0 | |
let g:ctrlspace_use_tabline=0 | |
if exists("+showtabline") | |
function GoBuffer(direction) | |
let direction = a:direction | |
let t_current = tabpagenr() | |
let b_current = bufnr('%') | |
let b_list = ctrlspace#bufferlist(t_current) | |
let first = -1 | |
let selected = -1 | |
let b_items = items(b_list) | |
for i in range(0, len(b_list) - 1) | |
let b = b_items[i] | |
if b[0] == b_current | |
if direction == "next" | |
let sel_index = (i+1)%len(b_list) | |
let selected = b_items[sel_index][0] | |
else | |
let selected = b_items[i-1][0] | |
endif | |
break | |
endif | |
endfor | |
if selected == -1 | |
let selected = first | |
endif | |
silent! exe ":b " . selected | |
endfunction | |
function Smallify_Number(nb) | |
let nb = a:nb | |
let small_numbers = ["⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"] | |
let ret = '' | |
if nb >= 10 | |
let ret .= small_numbers[nb/10] | |
end | |
let ret .= small_numbers[nb%10] | |
return ret | |
endfunction | |
function MyTabLine() | |
" exit if ctrl-space called : bug occurs when not in path of workspace | |
" if bufname('%') == '__CS__' | |
" return | |
" endif | |
let ret = '' | |
let l_left = '' | |
let t_last = tabpagenr("$") | |
let t_current = tabpagenr() | |
let b_list = ctrlspace#bufferlist(t_current) | |
" &columns hidden | |
" < --- 126 --- >< ---------174 ---------> | |
" | |
" viewable, l_right | |
" <---110---><16> | |
" | |
" l_left + l_right | |
" < ---------------- 300 ----------------> | |
" <+-------->----------------------------- | |
" <-----+--->----------------------------- | |
" ---------------<-----+--->-------------- | |
" -----------------------------<-----+---> | |
" -----------------------------<--------+> | |
" Pre Build l_right | |
let ret_right = '' | |
let l_right = '' | |
" Show Name of Current Tab | |
let ret_right .= '%#TabLineFill#' | |
let t_title = gettabvar(t_current, 'ctrlspace_label') | |
let ret_right .= ' ' . t_title | |
let l_right .= ' ' . t_title | |
" Check if another tab has an unsaved buffer | |
let next_color = '' | |
for t in range(1, tabpagenr("$")) | |
if ctrlspace#tab_modified(t) | |
let next_color = '%#TabLineSel#' | |
endif | |
endfor | |
if next_color == '' | |
let next_color = '%#TabLine#' | |
endif | |
let ret_right .= next_color | |
" Show Number of the current tab | |
let ret_right .= Smallify_Number(t_current) | |
let l_right .= Smallify_Number(t_current) | |
let len_viewable = &columns - len(l_right) - 2 | |
" Start Building l_left | |
" Add Separator | |
let ret .= '%#TabLine#' | |
let ret .= '| ' | |
let l_left .= '| ' | |
" Find index of current & len until each buffer | |
let index_current = -1 | |
let starting_positions = {} | |
for i in range(0,len(b_list) - 1) | |
let starting_positions[i]=len(l_left) | |
let b = items(b_list)[i] | |
let b_nb = b[0] | |
let b_name = b[1] | |
if bufnr('%') == b_nb | |
let index_current = i | |
endif | |
let l_left .= b_name | |
let l_left .= Smallify_Number(i) | |
let l_left .= ' | ' | |
endfor | |
" Find out from which buffer we are going to add to tabline | |
let start = 0 | |
if len(l_left) > len_viewable && has_key(starting_positions, index_current) "when __CS__ no index_current | |
let min_start = starting_positions[index_current] - (len_viewable/2) | |
if starting_positions[index_current] > (len(l_left) - len_viewable) | |
let min_start = len(l_left) - len_viewable - len(l_right) | |
endif | |
for i in range(0,index_current) | |
if starting_positions[i] > min_start | |
let start = i | |
break | |
endif | |
endfor | |
endif | |
" Show Buffers from this current Tab-Space " | |
let l_left = '' | |
for i in range(start, len(b_list) - 1) | |
let b = items(b_list)[i] | |
let b_nb = b[0] | |
let b_name = b[1] | |
" Act on current buffer & Set Color | |
if bufnr('%') == b_nb | |
let ret .= '%#TabLineSel#' | |
let pos_current = len(l_left) | |
else | |
let ret .= '%#TabLine#' | |
endif | |
" Add Buffer Name | |
let ret .= fnamemodify(b_name,":t") | |
let l_left .= fnamemodify(b_name,":t") | |
" Reset Color and | |
" Add Buffer Number | |
" Highlight non saved | |
if getbufvar(str2nr(b_nb), '&modified') | |
let ret .= '%#TabLineFill#' | |
let ret .= Smallify_Number(b_nb) | |
let l_left .= Smallify_Number(b_nb) | |
let ret .= '%#TabLine#' | |
else | |
let ret .= '%#TabLine#' | |
let ret .= Smallify_Number(b_nb) | |
let l_left .= Smallify_Number(b_nb) | |
endif | |
" Add Separator | |
let ret .= ' | ' | |
let l_left .= ' | ' | |
" Break if l_left > visible | |
if len(l_left) > len_viewable | |
break | |
endif | |
endfor | |
" Start Align Right | |
let ret .= '%=' | |
let ret .= ret_right | |
" Show Nr of Current Tab | |
" if t_current == 1 | |
" let ret .= '1..' | |
" elseif t_current == t_last | |
" let ret .= '..' . t_current | |
" else | |
" let ret .= '.' . t_current . '.' | |
" endif | |
" let ret .= (tabpagenr('$') > 1 ? '%999XX' : 'X') | |
return ret " . | |
" \ len(ret) . '=' . | |
" \ len(l_left) . '+' . | |
" \ len(l_right) . '<' . | |
" \ &columns . '<' . | |
" \ winwidth(1) . '@' . | |
" \ pos_current | |
endfunction | |
set stal=2 | |
set tabline=%!MyTabLine() | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment