Skip to content

Instantly share code, notes, and snippets.

@ujihisa
Created May 14, 2011 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ujihisa/972160 to your computer and use it in GitHub Desktop.
Save ujihisa/972160 to your computer and use it in GitHub Desktop.
" kana's useful tab function {{{
function! s:move_window_into_tab_page(target_tabpagenr)
" Move the current window into a:target_tabpagenr.
" If a:target_tabpagenr is 0, move into new tab page.
if a:target_tabpagenr < 0 " ignore invalid number.
return
endif
let original_tabnr = tabpagenr()
let target_bufnr = bufnr('')
let window_view = winsaveview()
if a:target_tabpagenr == 0
tabnew
tabmove " Move new tabpage at the last.
execute target_bufnr 'buffer'
let target_tabpagenr = tabpagenr()
else
execute a:target_tabpagenr 'tabnext'
let target_tabpagenr = a:target_tabpagenr
topleft new " FIXME: be customizable?
execute target_bufnr 'buffer'
endif
call winrestview(window_view)
execute original_tabnr 'tabnext'
if 1 < winnr('$')
close
else
enew
endif
execute target_tabpagenr 'tabnext'
endfunction " }}}
" <space>ao move current buffer into a new tab. {{{
nnoremap <silent> <Space>ao :<C-u>call <SID>move_window_into_tab_page(0)<Cr>
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment