0

Suppose you are trying to create a set of mappings such that pressing <C-t> followed by a number # would alternate to the respective tab at index #. I know that using a loop, I can do:

" Map alt-x keys to jump to a tab
for i in range(1, 9)
  execute "nmap \<C-t>" . i . "> " . i . "gt"
endfor

Such a solution, however, hast the disadvantage of allowing only a mapping that recognizes up to 9. Is there a more general way to have a mapping depend on a count pressed at the end of the mapping, for instance such that hitting <C-t>14 would focus tab number 14?

Note: the above is just an example, I am interested in this regardless of tabs per se.

1 Answer 1

1

The problem with having a count at the end is Vim will have to wait to see if more keys are going to be pressed. E.g. <c-t>1 might mean you are supplying a count of 1 or maybe it will end up being 14.

The other problem is you have to make all these mappings. So if you want to support a count up to 15, then you need 15 mappings.

Options:

  • Provide a terminating sequence. e.g. <c-t>{count}<c-t>. Still have to create lot of mappings, but it will allow for a "count"
  • Simply use Vim's native <count> which is a proceeds the map sequence. e.g. 4gt. This means one mapping and the count will work correctly.

Aside about tabs and buffers

Your mappings suggest a heavy tab centric workflow. I know it might sound weird but maybe try and use less tab panes together with a more buffers centric workflow. Here are some nice posts about it:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.