Skip to content

Instantly share code, notes, and snippets.

@bootleq
Forked from ujihisa/space-ao.vim
Created July 3, 2011 03:17
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 bootleq/1061925 to your computer and use it in GitHub Desktop.
Save bootleq/1061925 to your computer and use it in GitHub Desktop.
See first comment
" Modified from kana's useful tab function {{{
function! s:move_window_into_tab_page(...)
" Move the current window into target_tabpagenr.
" a:1 - target_tabpagenr : if not set, move into new tab page.
" a:2 - open_relative : open new tab aside current tab (default 1).
let target_tabpagenr = a:0 > 0 ? a:1 : 0
let open_relative = a:0 > 1 ? a:2 : 1
if target_tabpagenr > tabpagenr('$')
let target_tabpagenr = tabpagenr('$')
endif
let original_tabnr = tabpagenr()
let target_bufnr = bufnr('')
let window_view = winsaveview()
if target_tabpagenr == 0
tabnew
if ! open_relative
tabmove
endif
execute target_bufnr 'buffer'
let target_tabpagenr = tabpagenr()
else
execute target_tabpagenr 'tabnext'
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>
" }}}
@bootleq
Copy link
Author

bootleq commented Jul 3, 2011

  • Take arbitrary number of arguments.
  • Add argument to open new tab aside current tab.
  • Change validation of invalid target_tabpagenr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment