Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same file on multiple tabs support #631

Closed
petersohn opened this issue Oct 18, 2016 · 12 comments · Fixed by #1011
Closed

Same file on multiple tabs support #631

petersohn opened this issue Oct 18, 2016 · 12 comments · Fixed by #1011

Comments

@petersohn
Copy link

Is there a way to open the same file in multiple tabs? If I select a file that is open somewhere, then NerdTree will jump to it, even if it is in a different tab. Is there a way to disable this feature? Or to disable it only if the file is open on a different tab, but not if in a window on the current tab?

@xinxingzhao
Copy link

About buffers, windows, tabs https://sanctum.geek.nz/arabesque/buffers-windows-tabs/

@petersohn
Copy link
Author

petersohn commented Oct 19, 2016

@xinxingzhao What do you imply with that comment? I know what tabs are about in vim, that's why I'm asking for this feature.

@xinxingzhao
Copy link

@petersohn I read vim help about buffers: A buffer is a file loaded into memory for editing. I think a file just has a buffer in vim. And, a buffer can has multiple windows, a tab can has multiple windows. In my view, there are buffers not associated with tabs. When you open three files in three tabs, vim will create three buffers. Then you close two tabs, the three buffers keep open.

I am sorry for my English!

@petersohn
Copy link
Author

That is exactly what my problem is. Normally, in vim, I can open the same
file in multiple windows or tabs. My problem is that it's not possible with
NerdTree. If I select a file that is open in a window anywhere, NerdTree
jumps to it instead of opening the file on the "current" window. This is
especially annoying if it is on a different tab, because different tabs
have different NerdTree instances (which, according to the FAQ,
intentional). So if I open NerdTree again in that tab, I have to start
navigating from scratch.

Moreover, if NerdTree jumps to a file (buffer) in another tab, the NerdTree
window remains open in the old tab. This problem would be worth another
issue though.

On 20 October 2016 at 03:40, xinxingzhao notifications@github.com wrote:

@petersohn https://github.com/petersohn I read vim help about buffers:
A buffer is a file loaded into memory for editing. I think a file just has
a buffer in vim. And, a buffer can has multiple windows, a tab can has
multiple windows. In my view, there are buffers not associated with tabs.
When you open three files in three tabs, vim will create three buffers.
Then you close two tabs, the three buffers keep open.

I am sorry for my English!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#631 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACsSv9tnuTZHj5c7gh9GhV9UlqCsdSxlks5q1saCgaJpZM4KZr14
.

Péter

@xinxingzhao
Copy link

@petersohn As far as I am concerned, NERDTree has't this feature.

@petersohn
Copy link
Author

Well, it does that for me (only NerdTree, I can open files normally with :edit). I can't find an option in the help that would control this behavior. My NerdTree related options are these:

let g:NERDTreeDirArrows=0
let g:NERDTreeMapOpenSplit = 's'
let g:NERDTreeMapOpenVSplit = 'v'
let g:NERDTreeIgnore = ['\.o$', '\.o-.*$', '\.pyc$', '^\..*\.sw.$', '^\.git$']
let g:NERDTreeQuitOnOpen = 1
let g:NERDTreeShowHidden = 1
let g:NERDTreeWinSize = 50

@PhilRunninger
Copy link
Member

@petersohn, this is what I discovered in my short investigation. Using the default mappings...

  • t or T will always create a new tab and open the file there.
  • o will move you to a different tab if the file is open there and not in the current tab.
  • go will open the file in the current tab, even when it's already open in another tab.
  • s, i, gs, and gi will split the current tab, and open the file there, even when it's open in another tab.

If I understand your question correctly, the o command is giving you trouble. What you need to do, then, is use go first, followed by o or Enter.

Note: NERDTree's behavior may have changed since you raised the issue.

@lifecrisis
Copy link
Contributor

I can understand why @petersohn is complaining.

I think the solution would be to re-map <CR> to open the file in the current tab always. We could then leave o to possibly reuse a window that exists in another tab. I like this solution because it gives the user an option of how to open a file... Also, using two keys to do exactly the same thing seems wasteful.

However, this is a major change (<CR> may be used in all kinds of custom mappings), so we should save it for NERDTree v6.0.0.

@PhilRunninger, what do you think?

@PhilRunninger
Copy link
Member

@lifecrisis, that sounds good to me.

With this being the first mention of v6.0, I created a project in the repo to track it. I figured "why not try it, and see how it works?". Feel free to edit its description with ideas you have for it, and I'll do the same.

@PhilRunninger
Copy link
Member

@petersohn , Can you give the referenced PR a try and let me know if it meets your needs? Thanks.

@ghost
Copy link

ghost commented Aug 24, 2020

Just found out that it was a merge above that enabled this. Thanks guys, that's very useful!
Leaving my original comment here for search engines:


I'm using "no side-window, only tabs" workflow -- using :tabe . and then opening a file in that exact tab, even if it was open before. The following setting in $MYVIMRC makes <CR> on a file to open it in that existing tab:

let NERDTreeCustomOpenArgs={'file':{'reuse':'currenttab'}}

i.e. that makes <CR> equivalent to go.

o still tries to switch to the leftmost tab with that file, when you need that behavior.
I still haven't find a way to close that new :tabe . tab after o switches, but that's no big deal (keepopen doesn't help with that).

@PhilRunninger
Copy link
Member

@ghtmpn , the keepopen bug was recently reported. See #1168. It's probably the next one I'm going to tackle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants