Is there a vim command to relocate a tab?

前端 未结 7 1677
南笙
南笙 2021-01-29 18:16

How can I change the position / order of my current tab in Vim? For example, if I want to reposition my current tab to be the first tab?

7条回答
  •  甜味超标
    2021-01-29 19:10

    For some reason, the function answer stopped working for me. I suspect a conflict with vim-ctrlspace. Regardless, the math in the function answer is unnecessary, as Vim can move tabs left and right with built in functions. We just have to handle the wrapping case, because Vim is not user friendly.

    " Move current tab into the specified direction.
    "
    " @param direction -1 for left, 1 for right.
    function! TabMove(direction)
        let s:current_tab=tabpagenr()
        let s:total_tabs = tabpagenr("$")
    
        " Wrap to end
        if s:current_tab == 1 && a:direction == -1
            tabmove
        " Wrap to start
        elseif s:current_tab == s:total_tabs && a:direction == 1
            tabmove 0
        " Normal move
        else
            execute (a:direction > 0 ? "+" : "-") . "tabmove"
        endif
        echo "Moved to tab " . tabpagenr() . " (previosuly " . s:current_tab . ")"
    endfunction
    
    " Move tab left or right using Command-Shift-H or L
    map  :call TabMove(-1)
    map  :call TabMove(1)
    

提交回复
热议问题