make nerdtree never open a third window - vim

When using NERDTree, I often have the situation where I close all existing buffers (except the NERDTree buffer), and then start opening fils from NERDTree again.
When doing this, NERDTree opens the files in a new split window, i.e. I have NERDTree at the left side, and on the right side two windows on top of each other, an emtpy buffer and the file I wanted to open.
What I want to happen is that NERDTree opens the file in the right window without splitting it.
Is there a way to tell NERDTree to never open a new window, if there is already one it could use? I tried using the "o" command, but that works exactly like the Enter command.

Have you checked all the mappings from the documentation
o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|
O.......Recursively open the selected directory..................|NERDTree-O|
x.......Close the current nodes parent...........................|NERDTree-x|
X.......Recursively close all children of the current node.......|NERDTree-X|
e.......Edit the current dif.....................................|NERDTree-e|

I finally got around to look at the nerdtree code, and I found the fix for my problem: I had to change the plugin.
I created a pull request for my changes on github:
https://github.com/scrooloose/nerdtree/pull/102
Update: Actually, the problem was a script I was using that set buftype=nofile for an empty buffer (it should set buftype=). After changing that, my problem went away.

Related

Vim, how to make Netrw to replace current open file instead of split opening new window, when you press preview or create new file commands?

Recently I've been using netrw. I've put these four lines on my .vimrc:
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_winsize = 25
map <C-n> :Lexplore <CR>
And I can easily toggle Lexplore and browse through the files to edit them. In this mode when I press Enter on any file on left hand side Netrw, it replaces the file in the right hand side window with new file; exactly what I want.
Problems start when I want to preview a file with "p" command on netrw or create a new file with "%" command. In former case (Preview) it split to the new window but I want it again to replace the file in right hand side window just like when I press Enter to to edit the file. And in latter case (creating a new file) it replaces the Lexplore (Netrw in the left hand side) instead of replacing the file on the right hand side window.
Is there any way that I can fix these issues? I've tried a lot of Netrw commands but nothing gives me what I want.
The "p" netrw command is mostly just pedit. So, assuming you don't already have a preview window, just press <cr> atop the file you want to preview and then :set pvw. That will make the window holding the file the preview window.
The second issue concerns "%" to create a new file. I'll think this over, but I think perhaps the better behavior is as you suggest -- keep the Lexplore window but open the new file in the editing window.
Please try version 171e of netrw which you can find at my website.
I believe this is related to a bug in vim. Once you use :Lexplore it apparently changes the g:netrw_chgwin option permanently, so whenever you try to pres <CR> in any netrw window, it will always open in a new window.

NERDTree and vim-windows

I like to have two or three vertical windows with code and a NERDTree to the left, among other things. From any of these windows I'd like to instantly jump to the NERDTree window, and when I choose to edit a file, I'd like that file to show up in the window I was in.
Are these things possible with the current state of the NERDTree plugin? It seems to me that :NERDTreeToggle is supposed to do the first thing I ask for according to the help, but no matter how I open a file, it always shows up in the window right next to my NERDTree.
Try :NERDTreeFocus to jump to the NERDTree window from any open window. This was added relatively recently, it seems:
https://github.com/scrooloose/nerdtree/pull/132

Need some help configuring Vim

I'm new to Vim (almost new) and have some questions.
The problem came from the following:
I have NERDTree and MiniBufExplorer plugins (I like them very much!).
I have mapped Ctrl-F to show up MiniBufExplorer window.
So when I focus on tree window, then push Ctrl-F, find a file I want and then press Enter, the resulting file opens in tree window (which was previous one). So, I want to have a window with a specific Name/ID and tell MiniBufExplorer to always open buffers there. In most cases I don't use split windows so it would not be a problem for me to open buffers always in same window.
I have looked into manual of Vim but didn't found any reference to window's ID, so I wonder if there is a way to give an ID to window and then configure buffer explorer to always open buffers there.
Thanks for help in advance.
There is a switch to tell MiniBufExplorer to try to open files in a buffer that is modifiable (that is to say, not NERDTree):
let g:miniBufExplModSelTarget = 1
Prevent opening files inside NERDTree or MiniBuffExplorer

Opening the most recently hidden buffer in Vim

Assuming that I have two buffers. One is NERDTree, the other is an actually file I'm editing. I accidentally open an another file from NERDTree and the new file hides the previous file I was editing.
A similar case occurs whether I use NERDTree or not.
How can I bring back the previous state by opening the mostly recently hidden file? I'm using the word "hide" because this is probably not "closing".
I use ctrl-6 to switch back to the previous buffer in the window.

VIM: How can i open a file at right side as vsplit from a left side NerdTree panel?

I installed NerdTree plugin.
How can i open a file at right side as vsplit from a left side NerdTree panel ?
To make vsplit put the new buffer on the right of the current buffer:
set splitright
Similarly, to make split put the new buffer below the current buffer:
set splitbelow
I haven't tried this with NerdTree, however.
There's a s command, but it opens a file split to the left of current buffer. Though you can press Ctrl+W r to swap windows then.
This is a bit of a hack, but how I do it is this:
Put cursor in window I want to open file into
Hit <leader>n<leader>n (this closes NERDtree and then opens it again with the cursor in NERDtree)
Select the file
On my system this opens it on the last window I was just on if the file isn't already open on my screen.
Start in the window you want to open your file into.
Hit <leader>n<leader>n to close and reopen NERDTree
Select the file you want!
A quick C-w = will get your windows back to proper proportions.
Not sure if anyone else is still struggling with this, but here's how I dealt with it.
You can use
:ls
to list the available buffers. Which would look something like:
1 "foo.txt"
2 "blame_the_user.java"
:b1 to select foo.txt
:b2 for blame_the_user.java
This method can be done from any window setup using :sp or :vs.
Open the buffers you want to split first.

Resources