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?
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)