Skip to content

Instantly share code, notes, and snippets.

@jondkinney
Created September 3, 2013 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jondkinney/6419600 to your computer and use it in GitHub Desktop.
Save jondkinney/6419600 to your computer and use it in GitHub Desktop.
Vim tab junk
" TABS
" ----
function! MoveCurrentTab(value)
if a:value == 0
return
endif
let move = a:value - 1
let move_to = tabpagenr() + move
if move_to < 0
let move_to = 0
endif
exe 'tabmove '.move_to
endfunction
" switch tab order with Ctrl+<left>/<right>
map <Esc>[C :call MoveCurrentTab(1)<Esc>
map <Esc>[D :call MoveCurrentTab(-1)<Esc>
" previous tab(F11), next tab (F12)
nmap <F11> :tabp<CR>
nmap <F12> :tabn<CR>
" Load up all buffers into tabs
nmap <localleader>bt :tab sball<CR>
function! MoveToPrevTab()
"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! MoveToNextTab()
"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
map <Esc>[B :call MoveToNextTab()<CR>
map <Esc>[A :call MoveToPrevTab()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment