Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: can global marks switch tabs instead of the file in the current tab?

Tags:

vim

tabs

I'm in the process of learning vim, and i just learned about marks. Before this i found it useful to have all the source code files i'm working on in their own tabs. When i found out about "global" (capital letter) marks i thought it would be a great way to switch to a tab which already has the marked file open, and scroll to the correct spot in a quick way. However, i found out that jumping to a mark in a different file simply changes the file which the current tab is displaying, and this messes up my tabs setup. Is there a way to make the marks work with the tabs in the way that i want?

like image 632
Eskil Avatar asked Jul 21 '10 07:07

Eskil


People also ask

How do you switch tabs in Vim?

To switch to the next tab, use :tabn, and to switch to the previous tab, use :tabp (short for tabnext and tabprevious respectively). You can also jump over tabs by using :tabn 2, which will move to the second next tab. To jump to the first tab, use :tabr (tabrewind) and to jump to the last tab use :tabl (tablast).

How do tabs work in Vim?

To directly move to first tab or last tab, you can enter the following in command mode: :tabfirst or :tablast for first or last tab respectively. To move back and forth : :tabn for next tab and :tabp for previous tab. You can list all the open tabs using : :tabs. To open multiple files in tabs: $ vim -p source.

How do I get a new tab to open in a buffer?

This utilizes the command :tabnew , in which opens a new tab with the argument % , which expands to the currently selected buffer's file.


2 Answers

The problem is that the mark-jumping commands are designed to move to the mark within the current window as there can theoretically be many windows to the same file. You need to switch to a new window first using :sbuf or :tabnext or CTRL+WW. If you have set switchbuf=useopen,usetab then using :sbuf <otherfile> first will be sufficient to jump to the other tab where your file is open. But 'A will not create a new window for you (or re-use an existing one in another tab).

You can probably create a mapping for ' and ` which uses getpos(), setpos(), :sbuf and switchbuf to jump to an existing window in another tab, but it would involve writing a page of vimscript.

See :help switchbuf and :help getpos() and :help setpos().

like image 185
too much php Avatar answered Nov 11 '22 19:11

too much php


Tabs may not be the best way to do what you are trying to do. When a file is open, it isn't necessarily open in just one tab. It's open in a buffer, which is a concept not tied to a tab.

In fact, you can have the same buffer open in multiple tabs (or even multiple panes within the same tab). A tab is more like a window into one or more of your currently open buffers.

It may be better to learn about how to switch between buffers in your current tab or pane. Just a suggestion.

like image 42
thomasrutter Avatar answered Nov 11 '22 19:11

thomasrutter