Open Nerdtree file in non-adjacent split
Asked Answered
R

2

16

Normally I switch over to the Nerdtree file buffer by hitting Ctrl+H twice to move the cursor over to the left edge of the screen. However, this means that when I open files, they are always in the split adjacent to the NERDTree window. How can I open files in the split that's not adjacent to the NERDTree window?

Reproduction answered 13/1, 2012 at 18:50 Comment(0)
I
22

NERDtree will open a file in the previous window if you press o or enter. You can open it in a split of the previous window by pressing i, or in a vertical split by pressing s.

It sounds like you have Ctrl-H mapped to Ctrl-W h. The trick to not having NERDtree open the file into a window that is adjacent to the NERDTree window is to not have the adjacent window be the previous window.

To achieve this, toggle the NERDTree window closed. (:NERDTreeToggle, or whatever your mapkey is to toggle NERDTree). Then move to the appropriate window you want to open the file in. Then toggle NERDTree open again. Now you can open the file in the previous window that you were in using o or enter... or in splits using i or s.

To save having to toggle the NERDTree window open/close, you may want to set the option NERDTreeQuitOnOpen. Then you just need to open NERDTree when you're in a window that you intend to open a file into.

Inconstant answered 13/1, 2012 at 22:58 Comment(2)
This doesn't seem to work well when splitting with 'i'. Is that a NerdTree bug?Brookbrooke
I've noticed the same, i always opens in a horizontal split adjacent to NERDtree, regardless of the last active windowProven
C
0

I usually use :NERDTreeFind in order to move from the right split window to the NERDtree on the very left.

This command shows the currently open file within the NERDtree window. Based on this, the previous window is the one on the right side. This of course only works conveniently if the file you want to open is close in the directory tree to the file already open.

To quickly access :NERDTreeFind, I mapped it to Ctrl + m in my ~/.vimrc:

nnoremap <C-m> :NERDTreeFind<CR>
Callant answered 4/9, 2020 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.