Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch to a particular tab by typing its name in Vim?

Tags:

vim

tabs

I've already seen Switching to a particular tab in VIM.

but I'd like to know whether it's possible to switch to a particular tab thanks to its name, not thanks to its number (which I find not very natural) (with code completion when we type only the first letter of the filename inside the tab).

like image 727
ThePhi Avatar asked Nov 22 '15 08:11

ThePhi


People also ask

How do I go to a specific tab in Vim?

In gnome-terminal, I can just press Alt + ( 1 , 2 , 3 , etc.) to switch to specific tabs. I can also use Ctrl + ( PgUp / PgDn ) to cycle through tabs (admittedly less convenient, but it can be remapped). If I want to use vim tabs instead of gnome-terminal tabs, typing :tabn and :tabp is quite cumbersome.

How do I open multiple tabs in Vim?

Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do I open a new tab in Vim?

Opening a tab Probably the easiest to remember is to run the :tabnew command while in normal mode. This will open a new tab with an empty buffer. If you want to edit a file in the new tab, you can run :tabnew filename and Vim will load the file in the new tab.


1 Answers

Tab pages don't have names so there is simply no way to switch to a specific tab page by… its name.

The label in the tab widget is the name of the buffer displayed in the focused window in the corresponding tab page. Thus, it could be anything from foo.txt to [No Name] via [Quickfix List] or p/a/t/t/h/to/bar.js, none of which would be of any use. Even foo.txt would not be that useful because of the very nature of buffers which can be displayed in any number of windows in any number of tab pages.

See :help tab-page.

There is a very limited solution, though: :sbuffer is the only "buffer" command that respects the 'switchbuf' option and allows you to switch to a specific buffer where it is displayed instead of in the current window.

:set switchbuf=useopen,usetab
:sb foo.txt

See :help 'switchbuf' and :help :sb.

Anyway, it seems that you are using tab pages as file proxies. This is very bad idea: buffers are the real thing.

like image 129
romainl Avatar answered Nov 15 '22 10:11

romainl