more intelligent global bookmarks in vim - vim

Here's how global bookmarks work.
Let's say I have two tabs in my vim session. One showing foo.txt, one showing bar.txt. I go to line 10 in foo.txt and hit mA
Then I go to the other tab, showing bar.txt. I hit `A, and the workspace on that tab opens foo.txt, putting my cursor on line 10.
So now I have two tabs, both showing foo.txt. This is less than ideal.
How I want it to work is, if one of my active workspaces on any tab is showing the file I the bookmark system is trying to navigate too, move my focus to that tab. If the file isn't open, sure - open it in my active workspace.
Is there any way to make this possible?
Thanks!

This is not a problem with Vim's global bookmarks. It's a problem with Vim's tabs.
In most text editors, tabs serve as a list of currently open files, but in Vim, the buffer list serves this purpose. If you think of a tab in Vim as being like a saved layout for split windows, then you'll meet less friction. This answer sums it up nicely, and I made a screencast to try and explain how tabs can be used.

Here is a script that answers your initial question. But as far as I'm concerned, nelstrom is right: tabs are not meant to contains the others files, but other layouts.
How do I jump to markers within different tabs in vim?

Related

How to open a file into the right editor (of split view)? [duplicate]

When I switch between files (Using ctrl-n for examples) in different editors, intellij always opens the file in the original editor the tab for the file is located. Coming from a vim background this seems counter intuitive for me. Is there a way to force intellij to always open the file in the same editor window?
Please vote for the following related issues:
IDEA-67559 Opening a file when there are multiple file groups may re-open in a different group rather than opening in the current group
IDEA-81628 Navigation within same file mistakenly leaves split editor
When using Ctrl-Shift-N to open the desired file, Shift-Enter to confirm will maintain the focused tab group.

In vscode, how to put editor regions inside tabs, and not the other way around?

I've been trying Visual Studio Code for a few days, and it's the first editor that I used in years that makes me feel I could switch from my beloved vim.
Now, it's hard to get used to new habits when you have years of muscle memory, but I'm trying to keep an open mind. There's one thing that's bugging me, though, and I could not find a way to get around: it's the fact that editor regions and tabs are "swapped". Let me explain:
In vscode, you define editor regions by splitting your screen, then each region can contain as many tabs as you want.
My problem is, that does not fit my workflow. Here's what my workflow used to be with vim, where regions are inside a single set of tabs (I mainly work with Django):
In a first tab, I've split my editor in half and I'm editing my models.py and forms.py side by side.
In a second tab, I've split the editor in half, I'm editing my views.py on the left hand side, and the right hand side is again split horizontaly, allowing me to edit multiple templatetags files.
In a third tab, I'm editing my main template, and I don't split the editor since the file may contain very long lines.
In a fourth tab, I'm editing several html files and the editor is split multiple times.
Etc.
That way, I can very quickly go to edit my models, then my views, then the templates, and start over in quick iterations.
With vscode, where the tabs are inside the fixed regions, not so much.
So my question is, what solution could I use? Am I missing a big feature here? Are there any extension that would allow me to get my old workflow back?
I'm also open to suggestions about new workflows.
As #romainl pointed out: the workflow is different, it doesn't work that way with VS Code (and I know, I'm a vim user, too).
The best you can get that is vaguely close to what you're used to is to consider VS Code windows as you did with vim tabs.
To give you an idea using your example:
You open a VS Code window and open side by side models.py and forms.py
You hit Ctrl+Shift+N (or Command+Shift+N on a Mac) and open a new window. There you open your views.py on the left and split the right one horizontally for the templates.
You open a new window again and repeat.
This way you can switch between different layouts with Alt+Tab
(or Command+Tab).
You could speed this up a bit by saving different workspace files for different files that you want open, because I think (not 100% sure) that saving the workspace also saves the layout.
There's a couple of annoying things with this approach though:
If you have multiple windows open in general (say, a browser, slack app and so on), they'll also appear in the list when you try to switch.
I'm not sure if the open folder will be remembered when opening a new window, but you can work around that by saving the workspace and opening it.
It's annoying but at least there's already a feature request about this ( https://github.com/Microsoft/vscode/issues/41486 )

Using multiple files simultaneously with tabs in vim NERDTree

Okay, this has been asked before.
But the answers did not really cover what I was looking for. I do not even get the purpose of t shortcut, it just opens another nerdtree where I can't even open folders with enter.
What I would like to do is to open files in new tabs inside one nerdtree session, just like in any other non-terminal text editor.
Now, if I open another file with enter, it closes the previously edited file. It becomes quite tedious very fast while working on a project.
Anybody has a solution for this?

Better Tab Navigation in gVim

How can I get tabs in gVim to work like they do in most good IDEs? I say gVim specifically because that is the version of Vim that I use but I am open to alternatives.
I want the following things for my tabs:
Ctrl+Tab goes to the MRU (most recently used) tab.
Holding down Ctrl and then pressing Tab multiple times continues to change to the next most recently used tab every time you press Tab.
When ctags are built and working and you press Ctrl+], if this takes you to a different file it should open that file in a new tab or if a tab with that file is already open it should switch to that one.
Easy tab reordering with the mouse just by dragging them around.
I am posting all these as a single question because I am hoping there is a good single solution that will do all or most of these things instead of having to hack each customization in individually. I would think this would be the preferred behavior by most of us.
Vim has no built in MRU. There is at least one plugin for that, though, but I've never used it.
The tabs in Vim are not the same as the tabs in your IDE, they are more like perspectives. The equivalent of your IDE's tabs in Vim are buffers and "(split)windows". There are a number of ways to work with buffers including some native ones and a number of third party plugins. Some of these plugins have MRU-like features.
The Vim wiki has a bunch of pages about tabs.

vim - howto close all buffers in the current tab?

I know that using a command like:
:%bdelete
Using this command I can close all buffers, in all tabs, what I'd like to do is to close all buffers open in the current tab, is that possible?
Usage:
What I'd like to do, is to open ViM and load :VSTreeExplorer and then open related files in the same window switching between them using :next and :previous and then open other files a new tab (with VSTreeExplorer as well), when I need to clean one of the tabs, I would like to use whatever command that closes buffers in the current tab.
For now, what I do is use :%bd and then open the VSTreeExplorer and start over...
Thanks
If you're done with a tab you can just use :tabclose.
:windo bd will delete all buffers in the current tab.
Buffers are global to the Vim instance, not confined to a specific tab page. A tab page is simply a way to organize windows and windows are simply a way to display a buffer. Zero or more windows (and therefore tab pages) can display the same buffer. Getting used to this concept should help your workflow in Vim.
The Vim wiki has a couple pages that give some more explanation and tips for using tab pages.

Resources