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

4

92

I installed NerdTree plugin.

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

Dealfish answered 27/10, 2011 at 5:35 Comment(0)
U
94

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.

Unholy answered 27/10, 2011 at 6:54 Comment(4)
That's ok, but if i want to open another file typing s, then i get another splitted window, but i want to replace the older splited window with the current opened file, how can i do this ?Dealfish
It appears that after adding set splitright, as @PrinceGoulash suggested, s on a file inside NerdTree will open a split to the right without needing to do Ctrl-W r. If I understand you correctrly, if you want to stick to only two vertically split windows you can switch to the older window and open a new file inside it via NerdTree by just hitting Enter.Unholy
No, what i'm trying to say is that , there are two vsplit window, the left is the nerdtree menu, if i press "s" then it will come to the right side. no more vsplitted window will appear.Dealfish
@guru Then you want to 'open' the new window, not to 'split' it. A window is always opened in / replace the last selected buffer. Unfortunately it will most likely be the left one of your two opened ones. Not ideal, but one option could be to rotate the windows around via Ctrl+W R, then open the file and rotate back.Nightjar
V
176

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.

Velure answered 27/10, 2011 at 7:1 Comment(4)
ok, but how can i open a vsplited file replacing the older one ?Dealfish
@shibly If you have splitright set, then you can quit the file that is currently on the right, vsplit newfilename, and that will put the new file where the old one was. You can also do those in one line like this: q | vsplit newfilename. This assumes that the file on the right is the active one.Boccherini
just tested, splitright does work well with nerdtree. Do note that this will make all further splits horizontal instead of vertical unless one uses vsplitTransmittal
For lua config: vim.opt.splitright = trueLuanneluanni
U
94

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.

Unholy answered 27/10, 2011 at 6:54 Comment(4)
That's ok, but if i want to open another file typing s, then i get another splitted window, but i want to replace the older splited window with the current opened file, how can i do this ?Dealfish
It appears that after adding set splitright, as @PrinceGoulash suggested, s on a file inside NerdTree will open a split to the right without needing to do Ctrl-W r. If I understand you correctrly, if you want to stick to only two vertically split windows you can switch to the older window and open a new file inside it via NerdTree by just hitting Enter.Unholy
No, what i'm trying to say is that , there are two vsplit window, the left is the nerdtree menu, if i press "s" then it will come to the right side. no more vsplitted window will appear.Dealfish
@guru Then you want to 'open' the new window, not to 'split' it. A window is always opened in / replace the last selected buffer. Unfortunately it will most likely be the left one of your two opened ones. Not ideal, but one option could be to rotate the windows around via Ctrl+W R, then open the file and rotate back.Nightjar
O
4

This is a bit of a hack, but how I do it is this:

  1. Put cursor in window I want to open file into
  2. Hit <leader>n<leader>n (this closes NERDtree and then opens it again with the cursor in NERDtree)
  3. 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 in

Start in the window you want to open your file into.

After <code><leader>n<leader>n</code> you will be back in NERDTree

Hit <leader>n<leader>n to close and reopen NERDTree

Select the file you want to open!

Select the file you want!

A quick C-w = will get your windows back to proper proportions.

Okhotsk answered 26/9, 2016 at 23:18 Comment(1)
great solution. by <leader>n you mean <C-n>?Rutile
P
4

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.

Parimutuel answered 17/1, 2017 at 2:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.