Guest User

Untitled

a guest
Dec 9th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 3.89 KB | None | 0 0
  1. " tab pages {{{
  2. let mapleader=","
  3.  
  4. set tabline=%!MyTabLine()
  5. function MyTabLine()
  6.     let s = '' " complete tabline goes here
  7.     " loop through each tab page
  8.     for t in range(tabpagenr('$'))
  9.         " select the highlighting for the buffer names
  10.         if t + 1 == tabpagenr()
  11.             let s .= '%#TabLineSel#'
  12.         else
  13.             let s .= '%#TabLine#'
  14.         endif
  15.         " empty space
  16.         let s .= ' '
  17.         " set the tab page number (for mouse clicks)
  18.         let s .= '%' . (t + 1) . 'T'
  19.         " set page number string
  20.         let s .= t + 1 . ' '
  21.         " get buffer names and statuses
  22.         let n = ''  "temp string for buffer names while we loop and check buftype
  23.         let m = 0 " &modified counter
  24.         let bc = len(tabpagebuflist(t + 1))  "counter to avoid last ' '
  25.         " loop through each buffer in a tab
  26.         for b in tabpagebuflist(t + 1)
  27.             " buffer types: quickfix gets a [Q], help gets [H]{base fname}
  28.             " others get 1dir/2dir/3dir/fname shortened to 1/2/3/fname
  29.             if getbufvar( b, "&buftype" ) == 'help'
  30.                 let n .= '[H]' . fnamemodify( bufname(b), ':t:s/.txt$//' )
  31.             elseif getbufvar( b, "&buftype" ) == 'quickfix'
  32.                 let n .= '[Q]'
  33.             else
  34.                 let n .= pathshorten(bufname(b))
  35.                 "let n .= bufname(b)
  36.             endif
  37.             " check and ++ tab's &modified count
  38.             if getbufvar( b, "&modified" )
  39.                 let m += 1
  40.             endif
  41.             " no final ' ' added...formatting looks better done later
  42.             if bc > 1
  43.                 let n .= ' '
  44.             endif
  45.             let bc -= 1
  46.         endfor
  47.         " add modified label [n+] where n pages in tab are modified
  48.         if m > 0
  49.             "let s .= '[' . m . '+]'
  50.             "let s.= '+ '
  51.             let s.= '[+] '
  52.         endif
  53.         " add buffer names
  54.         if n == ''
  55.             let s .= '[No Name]'
  56.         else
  57.             let s .= n
  58.         endif
  59.         " switch to no underlining and add final space to buffer list
  60.         "let s .= '%#TabLineSel#' . ' '
  61.         let s .= ' '
  62.     endfor
  63.     " after the last tab fill with TabLineFill and reset tab page nr
  64.     let s .= '%#TabLineFill#%T'
  65.     " right-align the label to close the current tab page
  66.     if tabpagenr('$') > 1
  67.         let s .= '%=%#TabLine#%999XX'
  68.     endif
  69.     return s
  70. endfunction
  71.  
  72. function TabMovePrev()
  73.     "there is only one window
  74.     if tabpagenr('$') == 1 && winnr('$') == 1
  75.         return
  76.     endif
  77.     "preparing new window
  78.     let l:tab_nr = tabpagenr('$')
  79.     let l:cur_buf = bufnr('%')
  80.     if tabpagenr() != 1
  81.         close!
  82.         if l:tab_nr == tabpagenr('$')
  83.             tabprev
  84.         endif
  85.         sp
  86.     else
  87.         close!
  88.         exe "0tabnew"
  89.     endif
  90.     "opening current buffer in new window
  91.     exe "b".l:cur_buf
  92. endfunc
  93.  
  94. function TabMoveNext()
  95.     "there is only one window
  96.     if tabpagenr('$') == 1 && winnr('$') == 1
  97.         return
  98.     endif
  99.     "preparing new window
  100.     let l:tab_nr = tabpagenr('$')
  101.     let l:cur_buf = bufnr('%')
  102.     if tabpagenr() < tab_nr
  103.         close!
  104.         if l:tab_nr == tabpagenr('$')
  105.             tabnext
  106.         endif
  107.         sp
  108.     else
  109.         close!
  110.         tabnew
  111.     endif
  112.     "opening current buffer in new window
  113.     exe "b".l:cur_buf
  114. endfunc
  115.  
  116. nnoremap <Leader>j :call TabMovePrev()<CR>
  117. nnoremap <Leader>k :call TabMoveNext()<CR>
  118.  
  119. nnoremap <silent> <Leader>t :tabnew<CR>
  120. nnoremap <silent> <Leader>w :quit<CR>
  121. nnoremap <silent> J :tabprevious<CR>
  122. nnoremap <silent> K :tabnext<CR>
  123. nnoremap <Leader>J J
  124. nnoremap <Leader>K K
  125. nnoremap <Leader>1 1gt
  126. nnoremap <Leader>2 2gt
  127. nnoremap <Leader>3 3gt
  128. nnoremap <Leader>4 4gt
  129. nnoremap <Leader>5 5gt
  130. nnoremap <Leader>6 6gt
  131. nnoremap <Leader>7 7gt
  132. nnoremap <Leader>8 8gt
  133. nnoremap <Leader>9 9gt
  134. nnoremap <Leader>0 10gt
  135. " }}}
Add Comment
Please, Sign In to add comment