Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " tab pages {{{
- let mapleader=","
- set tabline=%!MyTabLine()
- function MyTabLine()
- let s = '' " complete tabline goes here
- " loop through each tab page
- for t in range(tabpagenr('$'))
- " select the highlighting for the buffer names
- if t + 1 == tabpagenr()
- let s .= '%#TabLineSel#'
- else
- let s .= '%#TabLine#'
- endif
- " empty space
- let s .= ' '
- " set the tab page number (for mouse clicks)
- let s .= '%' . (t + 1) . 'T'
- " set page number string
- let s .= t + 1 . ' '
- " get buffer names and statuses
- let n = '' "temp string for buffer names while we loop and check buftype
- let m = 0 " &modified counter
- let bc = len(tabpagebuflist(t + 1)) "counter to avoid last ' '
- " loop through each buffer in a tab
- for b in tabpagebuflist(t + 1)
- " buffer types: quickfix gets a [Q], help gets [H]{base fname}
- " others get 1dir/2dir/3dir/fname shortened to 1/2/3/fname
- if getbufvar( b, "&buftype" ) == 'help'
- let n .= '[H]' . fnamemodify( bufname(b), ':t:s/.txt$//' )
- elseif getbufvar( b, "&buftype" ) == 'quickfix'
- let n .= '[Q]'
- else
- let n .= pathshorten(bufname(b))
- "let n .= bufname(b)
- endif
- " check and ++ tab's &modified count
- if getbufvar( b, "&modified" )
- let m += 1
- endif
- " no final ' ' added...formatting looks better done later
- if bc > 1
- let n .= ' '
- endif
- let bc -= 1
- endfor
- " add modified label [n+] where n pages in tab are modified
- if m > 0
- "let s .= '[' . m . '+]'
- "let s.= '+ '
- let s.= '[+] '
- endif
- " add buffer names
- if n == ''
- let s .= '[No Name]'
- else
- let s .= n
- endif
- " switch to no underlining and add final space to buffer list
- "let s .= '%#TabLineSel#' . ' '
- let s .= ' '
- 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 TabMovePrev()
- "there is only one window
- if tabpagenr('$') == 1 && winnr('$') == 1
- return
- endif
- "preparing new window
- let l:tab_nr = tabpagenr('$')
- let l:cur_buf = bufnr('%')
- if tabpagenr() != 1
- close!
- if l:tab_nr == tabpagenr('$')
- tabprev
- endif
- sp
- else
- close!
- exe "0tabnew"
- endif
- "opening current buffer in new window
- exe "b".l:cur_buf
- endfunc
- function TabMoveNext()
- "there is only one window
- if tabpagenr('$') == 1 && winnr('$') == 1
- return
- endif
- "preparing new window
- let l:tab_nr = tabpagenr('$')
- let l:cur_buf = bufnr('%')
- if tabpagenr() < tab_nr
- close!
- if l:tab_nr == tabpagenr('$')
- tabnext
- endif
- sp
- else
- close!
- tabnew
- endif
- "opening current buffer in new window
- exe "b".l:cur_buf
- endfunc
- nnoremap <Leader>j :call TabMovePrev()<CR>
- nnoremap <Leader>k :call TabMoveNext()<CR>
- nnoremap <silent> <Leader>t :tabnew<CR>
- nnoremap <silent> <Leader>w :quit<CR>
- nnoremap <silent> J :tabprevious<CR>
- nnoremap <silent> K :tabnext<CR>
- nnoremap <Leader>J J
- nnoremap <Leader>K K
- nnoremap <Leader>1 1gt
- nnoremap <Leader>2 2gt
- nnoremap <Leader>3 3gt
- nnoremap <Leader>4 4gt
- nnoremap <Leader>5 5gt
- nnoremap <Leader>6 6gt
- nnoremap <Leader>7 7gt
- nnoremap <Leader>8 8gt
- nnoremap <Leader>9 9gt
- nnoremap <Leader>0 10gt
- " }}}
Add Comment
Please, Sign In to add comment