2

Instead of using tabnext and tabprevious is there a command or a plugin which can list your tabs vertically so you can navigate up and down and choose the one to switch to?

I am thing along the lines of the Ctrl-a " command in screen which lists your windows for you to select the one to switch to.

  • 1
    Does :tabs work for you? – Tumbler41 Apr 12 '17 at 21:33
  • @Tumbler41 what happens when you have more tabs than 0-9? Can you use the cursor keys to move up and down on the list? – vfclists Apr 12 '17 at 21:52
  • 1
    Yes, or you can use j and k. – Tumbler41 Apr 12 '17 at 21:56
  • One should not think of "tabs" in vim as "tabs" in most of the common applications. You probably want to use "buffers" instead. Confusion about this wording is very common, read this: stackoverflow.com/q/26708822/4568748 – Philipp Moers Apr 20 '17 at 8:36
  • If you really use more than 10 "tabs" (vim workspaces), I would be really interested to see your workflow ;-) – Philipp Moers Apr 20 '17 at 8:39
4

To expand on @Tumbler41's comment about :tabs, it shows you a list of tabs like :ls shows you buffers. But, there isn't a command to go directly to a tab from this list like using :b after :ls.

You can fake it by using :<count>tabdo:. The colon at the end is basically a no-op command that's considered a valid argument for :tabdo. To streamline this, you can turn it into a command:

command! T tabs|execute input('Select Tab: ').'tabdo:'

After the tabs are listed, you enter a number and press <cr> to jump to the tab. The same thing can be done with :ls:

command! L ls|execute input('Select Buffer: ').'b'

The caveat here is that if listing scrolls, you won't be able to scroll back up once the prompt is displayed. Another problem is that this accepts any input which aren't a valid command count.

Here's a version that's a little safer but more verbose:

command! T tabs|execute substitute(input('Select Tab: '), '^\d\+$', '\0tabdo:', '')

The substitution only adds tabdo: if the input is all digits. Otherwise, the input is executed as-is.

  • Is there a plugin for this, something like NERDtree's window that can be toggled in and out of view, then you select the tab to switch to? – vfclists Apr 24 '17 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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