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

Always opening NERDTree in current window and reuse instance #244

Closed
marlun opened this issue Mar 12, 2013 · 12 comments
Closed

Always opening NERDTree in current window and reuse instance #244

marlun opened this issue Mar 12, 2013 · 12 comments

Comments

@marlun
Copy link

marlun commented Mar 12, 2013

I read http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/ and as Drew says you can add let NERDTreeHijackNetrw=1 and NERDTree will open up in the current window if I do :e .. However it seems to be a new instance of NERDTree every time it's opened because it does not remember which folders I had open before like it does if I run :NERDTreeToggle. Is it possible to have both? Have NERDTree open in the current window and remember where it was (reuse the same instance)?

@LeonB
Copy link

LeonB commented Apr 23, 2014

I would really like this feature. Any ideas on how to accomplish this?

@knubie
Copy link

knubie commented Oct 6, 2015

Every time NERDTree creates an instance via the NERDTreeHijackNetrw function is assigns it a unique buffer name i.e. NERD_tree_1, NERD_tree_2, etc. Why it's designed this way is not entirely clear to me, but as it turns out you can easily switch to the first instance by typing :buffer NERD_tree_1 without ever having to create a new one.

So instead of editing the NERDTree source, I just created a mapping that looks like this:

nnoremap <leader>e :buffer NERD_tree_1<CR>

Hope this helps.

@pass86
Copy link

pass86 commented Oct 3, 2016

I like this feature too!

@scrooloose
Copy link
Collaborator

Hi, I have added a simple proof of concept for this in this branch: https://github.com/scrooloose/nerdtree/tree/reuse-win-tree

Try it out and let me know how you get on :)

@scrooloose
Copy link
Collaborator

@PhilRunninger any thoughts on this? It seems like The Right Way (TM) to go - at least in theory.

@PhilRunninger
Copy link
Member

I like the approach. I'm getting an error though. I think it's related to buffer 1 no longer being in my list as you loop through the list.

After entering :e .. for the second (maybe third) time...
image

@scrooloose
Copy link
Collaborator

Hmm, I cant reproduce this :-/

Can you give any more info about it?

@PhilRunninger
Copy link
Member

  1. :e .. opens a NERDTree
  2. Expand a folder, and open a file.
  3. :e .. again should open the same NERDTree buffer, but I get the error shown above.

It happens on the let nt = getbufvar(i, "NERDTree") statement when nt exists from the previous loop iteration, and is an incompatible type. If it's already an empty string, it cannot be set to a dictionary, and vice versa.

I added a new commit to fix it, but I don't know if I did it the correct way.

@scrooloose
Copy link
Collaborator

I still cant reproduce this. Vimscript is awesome! But I've merged it back into master (with your fix). Thanks for testing/feedback :-)

I've been using nerdtree with :e . at work for a few days and its actually pretty awesome.

@juanibiapina
Copy link
Contributor

This is awesome. Any tips on how to do the same with NerdTreeFind ?

zefei added a commit to zefei/nerdtree that referenced this issue May 15, 2018
In a multi-window workflow, it's often desirable to make NERDTree to
work in the current window instead of its side window. See issue preservim#244
for brief discussion.

Currently it's possible to use `:e <dir>` to achieve this for
`:NERDTree` command; but there are no workarounds for other functions
like opening bookmark, toggling nerdtree, finding current file, etc.

This commit adds an option to render NERDTree in current window instead
of side window, and modifies all relevant commands to respect the
option.
@hjdivad
Copy link

hjdivad commented Apr 16, 2020

@juanibiapina hjdivad/dotfiles@f030f34 might be close enough to want you want.

It relies on a mapping (in my case <leader>ne) and will make the opened NERDTree the implicit one for the tab (so it only really makes sense if you never want to use NERDTree on the sides) and finally NERDTReeFinds the buffer your window was editing.

You can likely tweak it according to your preferences.

@juanibiapina
Copy link
Contributor

I've actually rewritten most of NerdTree to work with splits properly: https://github.com/juanibiapina/vim-lighttree

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

No branches or pull requests

8 participants