Vim Tips Wiki
Register
m (→‎Comments: Use <pre> for code. sign comment)
Line 61: Line 61:
   
 
One more way:
 
One more way:
  +
<pre>
 
function MoveTabLeft()
 
let current_tab = tabpagenr()
  +
if current_tab > 1
 
let current_tab = current_tab - 2
 
execute 'tabmove' current_tab
 
endif
 
endfunction
   
function MoveTabLeft()
+
function MoveTabRight()
let current_tab = tabpagenr()
+
let current_tab = tabpagenr()
if current_tab > 1
+
execute 'tabmove' current_tab
 
endfunction
let current_tab = current_tab - 2
 
execute 'tabmove' current_tab
 
endif
 
endfunction
 
 
function MoveTabRight()
 
let current_tab = tabpagenr()
 
execute 'tabmove' current_tab
 
endfunction
 
 
map <Leader>tl :call MoveTabLeft()<CR>
 
map <Leader>tr :call MoveTabRight()<CR>
 
   
 
map <Leader>tl :call MoveTabLeft()<CR>
 
map <Leader>tr :call MoveTabRight()<CR>
  +
</pre>
  +
<small>--Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:77.232.5.123|77.232.5.123]] ([[User talk:77.232.5.123|talk]] • [[Special:Contributions/77.232.5.123|contribs]]) 20:44 Apr 1 2008</small><!-- Template:Unsigned -->
  +
----
   
   

Revision as of 19:10, 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
    "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

My mapping for them:

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

Comments

This looks like it might be promising, but you should explain better what it does, and how it's different from/why it can't use :help :tabmove or :help CTRL-W_T. --Fritzophrenic 16:06, 18 April 2008 (UTC)

One more way:

function MoveTabLeft()
  let current_tab = tabpagenr()
  if current_tab > 1
    let current_tab = current_tab - 2
    execute 'tabmove' current_tab
  endif
endfunction

function MoveTabRight()
  let current_tab = tabpagenr()
  execute 'tabmove' current_tab
endfunction

map <Leader>tl :call MoveTabLeft()<CR>
map <Leader>tr :call MoveTabRight()<CR>

--Preceding unsigned comment added by 77.232.5.123 (talkcontribs) 20:44 Apr 1 2008