0

I'm not familiar with vim code.

I tried to use vim as IDE, I setup NERDTree plugin.this is my problem:

assume I opened 4 files as tabs. if I press t on opened file already on NERDTree plugin, the file would be reopened in new tab. I prefer it switches to its tab that opened before. is there any way to do that

  • 1
    I don't know if it works with NERDTree, but adding something like set switchbuf=useopen,usetab,newtab often works. – Martin Tournoij May 18 at 20:34
  • could you please give me a precise code?that is not working on NERDTree – Hossein Vatani May 19 at 17:44
  • 1
    @HosseinVatani you just need to put Martin's code in your vimrc (to save the settings) or in the command line (if you only want to test it). – Biggybi Jun 18 at 3:33
0

If you know the file is opened use o. It will switch you to desired tab.

o: open in prev window
| improve this answer | |
  • when you used vim as IDE, many tabs opened and could not remember which one is opened. – Hossein Vatani May 18 at 7:54
0

You can probably write a bunch of Vim script to achieve the desired behaviour, but I'll suggest you take another route.

In Vim, what we know as tabs in other applications, are called buffers. They are a bit confusing at first because by default there's no buffer bar, so there's no way to quickly see all the open buffers. You can install a plugin that makes the tab line or status line to show you the loaded buffers, like tabline and wintabs, but there are better ways to navigate buffers. Using a fuzzy finder like FZF is nice because it only takes screen space while you are using it. And of course, you can use the native commands :ls (to list the buffers), :bnext (to jump to the next one), :bprev (to jump to the previous one). There are many more commands, see :help buffers for details.

Now you may be wondering if Vim buffers are like other application's tabs, what is a Vim tab? They are actually called "tab pages" (see :h tabpage) and their purpose is to hold one or more windows. That means you can have two tab pages, in one you can have two windows, side by side, in the other you could have three windows, one to the left, and the other two in the right halve, one below the other. The idea is that you can have different layouts and switch between them as desired. Plugins like DiffOrig and Mergetool are quite nice because instead of disrupting your windows layout, they create a new tab and close it once you are done.

Vim default tab line shows the buffer loaded in the currently focused window, and that makes tab pages to look like tabs in other apps. I think that's one of the reasons they are so confusing at the beginning.

If you are still not convinced I recommend you to read Buffers, windows, and tabs, and/or Vim tab madness. Both do a better job than me

| improve this answer | |
  • thanks for your explanation, I knew buffers and tabs and split and so on.FZF open file as a buffer not in its tab.i'd rather write some line code to achieve that. – Hossein Vatani May 18 at 9:38
  • I’m just curious: if you know Vim buffers are what other software call tabs and that Vim tabs are all about multiple windows, why do you want to keep one buffer per Vim tab? – Tae May 18 at 9:41
  • I keep NERDTree always open in left and active mouse, it is very fast by click on a file name in left. sometimes I navigate tabs by gt and {no}gt and .... when the same file opened many times, it reduces my speed of coding. I could handle my problem with :tabs, :buffers and so on but try to find a better way. – Hossein Vatani May 18 at 10:56
  • Vim tabs and vim buffers are not the same Tae; I find your explanation a bit confusing. I do agree one buffer per tab is not ideal, but your attempt to disambiguate them is, well, quite ambiguous. – D. Ben Knoble May 18 at 14:50
  • I really did a bad job because I know Vim tabs and Vim buffers are not the same. I edited this part "In Vim, what we know as tabs, are called buffers" because now I see it is confusing – Tae May 18 at 14:56

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.