2

This question is a follow up to this one (graphs copied from there). The OP was wondering how to split the pane of File 3 horizontally.

/========================================================\
|          |                      |                      |
|          |                      |                      |
|          |     file 1           |                      |
|          |                      |                      |
|          |______________________|                      |
| NERDTree |                      |     File 3           |
|          |                      |                      |
|          |    file 2            |                      |
|          |                      |                      |
\__________|______________________|______________________/

currently if I were to be on the File 3 pane, then click on ctrl+n to jump to nerdtree, then select <file name> + i, my expectation is to have this:

/========================================================\
|          |                      |                      |
|          |                      |                      |
|          |     file 1           |       File 4         |
|          |                      |                      |
|          |______________________|______________________|
| NERDTree |                      |                      |
|          |                      |                      |
|          |    file 2            |      File 3          |
|          |                      |                      |
\__________|______________________|______________________/

but instead i am getting this:

/========================================================\
|          |                      |                      |
|          |       file 1         |                      |
|          |______________________|                      |                      
|          |                      |                      |
|          |                      |                      |
|          |       File 2         |        file 3        | 
| NERDTree |                      |                      |
|          |______________________|                      |                      
|          |                      |                      |
|          |       file 4         |                      |
|          |                      |                      |
\__________|______________________|______________________/

The OP found the solution by using a mouse with mvim. I would like a solution without using a mouse since the one of the main reasons I use vim is not to use a mouse.

3

The linked question asks how to jump directly from File 3 window to NERDTree window without hopping through File 1 or File 2 window first. The OP's solution is to use the mouse to click on the NERDTree window. If you're just asking for a non-mouse way to do that then one answer is 2^wh. That is, hit 2 then Ctrl+W then H. (Refer to :h CTRL-W_CTRL-H)

However, I don't think that'll solve your problem. But this does, based on my testing: :set splitright. Setting this causes new vertical splits to open to the right rather than the left (the default). With this I can recreate your four windows with File 4 appearing in the same column as File 3 when I open it from NERDTree with s.

Update: At first I thought the precise layout of three-windows didn't matter but if you have to have it look like your first diagram then you'll need to use another approach: from File 3 window do :split then do the 2^wh command to go to NERDTree and, lastly, choose a file with o. You'll end up in the same four-window layout that you asked for and the cursor will be in the newly opened fourth window.

You could even add a mapping that will take care of the split and cursor move with a key press or two.:

:nnoremap <leader>n :split \| :2winc h<CR>

In Normal mode enter \n. Or change that to some other unused key combo.

Update 2: An upvote drew my eye to this answer of mine and it occurred to me that it would be more convenient if you could use one mapping to go from NERDTree and the first layout shown in the question to File 4 window of the second layout.

nnoremap <leader>o :2winc l \| split \| 2winc h \| norm o<CR>

Put the cursor on the file you want to open and instead of just hitting O (i.e. enter a lower case o) hit the leader key first then O. That's it. (There's nothing new as far as technique here, I'm just packaging things in a nicer way and saving someone from having to figure out the mapping.)

  • what is the reference for the 2 Ctrl + W h part? I tried it once and it worked, but i couldn't make it work again. this is the sequence: press on 2 and control (at the same time) then release the keys then press on shift + w + h. that doesn't work though – abbood Jan 14 '18 at 15:03
  • See my updated answer. It's conventional to use capital letters with <kbd> because that's what we have on our keyboards, not lower-case (though I had a typo with "h"...it's now <kbd>H</kbd>). If I wanted to denote a capital letter then you'd see <kbd>Shift</kbd> before it. The other notation, though, uses lower-case. – B Layer Jan 14 '18 at 15:11
  • you said Refer to :h CTRL-W_CTRL-H.. which reference are you talking about? i saw the help of nerd tree.. never found anything talking about that – abbood Jan 14 '18 at 17:42
  • i tried set splitright.. but same thing happened. See here – abbood Jan 14 '18 at 17:46
  • _ With this I can recreate your four windows with File 4 appearing in the same column as File 3 when I open it from NERDTree with s_ .. maybe if you explain to me the sequence of steps you do right from the beginning.. maybe i'm starting differently than you that's why i'm ending up with different results – abbood Jan 14 '18 at 17:50

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.