I can't really explain why it works like this, my best guess is that you more often need to go a tab by its index rather than going 3 tabs forwards.
However, if you really don't like how Vim works and want to be able to "undo" a 2gT
with 2gt
you can add the following to your vimrc:
function! Mygt(forward, count)
let loop = a:count
while loop > 0
if a:forward
normal! gt
else
normal! gT
endif
let loop = loop -1
endwhile
endfunction
nnoremap <silent> gt :<C-U>execute "call Mygt(1, " . v:count1 . ")"<CR>
nnoremap <silent> gT :<C-U>execute "call Mygt(0, " . v:count1 . ")"<CR>
The function Mygt()
is pretty straightforward: it takes 2 arguments, the first one is used to define if you want to go forward or backward in the list of tabs and the second one is how many tabs you want to skip. So it loops on the given count and repeats gt
or gT
according to the first parameter.
You can try it with :call Mygt(1, 2)
or :call Mygt(0, 4)
To make it easier to use, we also remap gt
and gT
:
<silent>
is used to avoid prompting the function called by the mapping. (see :h :map-<silent>
)
<C-u>
is used to remove characters on the command line, it is used to allow a count to the mapping (see :h c_CTRL-U
)
- We build the string which will contain the command to execute (e.g.
call Mygt(1, 3)
and execute it with execute
(see :h execute()
)
- And finally, we use the count given to the mapping with
v:count1
which will default to 1
if no count is given. (see :h v:count
and :h v:count1
)
All of this allows us to use gt
, gT
, 3gt
and 5gT
and get a "consistent" behavior.