Vim Tips Wiki
Register
No edit summary
No edit summary
Line 10: Line 10:
 
let l:tab_nr = tabpagenr('$')
 
let l:tab_nr = tabpagenr('$')
 
let l:cur_buf = bufnr('%')
 
let l:cur_buf = bufnr('%')
"write
 
   
 
if tabpagenr() == 1
 
if tabpagenr() == 1

Revision as of 14:49, 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

    let l:tab_nr = tabpagenr('$')
    let l:cur_buf = bufnr('%')

    if tabpagenr() == 1
        close!
        exe "0tabnew"
        exe "b".l:cur_buf
    else
        close!
        if l:tab_nr == tabpagenr('$')
            tabprev
        endif
        sp
        exe "b".l:cur_buf
    endif
endfunc

function MoveToNextTab()
    "there is only one window
    if tabpagenr('$') == 1 && winnr('$') == 1
        return
    endif

    let l:tab_nr = tabpagenr('$')
    let l:cur_buf = bufnr('%')
    if tabpagenr() < tab_nr
        close!
        if l:tab_nr == tabpagenr('$')
            tabnext
        endif
        sp
        exe "b".l:cur_buf
    else
        close!
        tabnew
        exe "b".l:cur_buf
    endif
endfunc

My mapping for them:

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