Vim Tips Wiki
No edit summary
m (Moving window between tabs moved to Move current window between tabs)
(No difference)

Revision as of 15:17, 18 April 2008

This two functions allows to move window between tabs:

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
    "openinng 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
    "openinng current buffer in new window
    exe "b".l:cur_buf
endfunc

My mapping for them:

	map <A-.> :call MoveToNextTab()<CR>
	map <A-,> :call MoveToPrevTab()<CR>