1

I've used two plugins with vim: Nerdtree and Taglist.

enter image description here

However, if I quit the opened file and open another file in the Nerdtree, it will become:

enter image description here

Which means that the new opened file is displayed at the bottom right corner.

How to manage the windows properly?

Initial state:

|          |             |         |
| Nerdtree | opened file | taglist |
|          |             |         |

close the opened file:

|                    |         |
|      Nerdtree      | taglist |
|                    |         |

reopen another file (this is not what I expected)

|                    |   taglist   |
|      Nerdtree      |-------------|
|                    | opened file |

What I expected is to get the layout just like the initial state.

|          |             |         |
| Nerdtree | opened file | taglist |
|          |             |         |
  • Please define what is "Properly"? Your examples shows the same (screenshots and pseudographics... – Maxim Kim Apr 14 at 9:35
  • @MaximKim "Properly" means that I don't like to get a file located at the bottom right corner, instead, I want to make the opened file stay in the middle zone of the terminal ( just like the initial state). – Yves Apr 14 at 9:42
  • Could you update your question? (Because "properly" for different vim users is different. In my case what you have is proper behavior) – Maxim Kim Apr 14 at 9:45
1

Nerdtree is the beast on its own (don't like it personally but anyway)

You can try following snippet of code:

func! MyOpen() abort
    let selected = g:NERDTreeFileNode.GetSelected()
    if selected != {}
        "remove everyother window
        wincmd o

        "open selected file in vertical split
        exe "vsplit " . selected.path.str()

        "open taglist in a vertical split
        "I don't have taglist installed so, use whatever taglist command is
        "instead of vslpit and enew.
        vsplit
        enew
    endif
endfunc
augroup nerdtree_open | au!
    au FileType nerdtree nnoremap <buffer> <CR> :call MyOpen()<CR>
augroup end

And use taglist commands instead of the last vsplit and enew (I don't have taglist installed and didn't find it on github)

Basically, it will always remove all your windows except nerdtree and vertically split selected filename, plus if you add there taglist commands -- it would probably what you want. But I am not sure. :)

| improve this answer | |
2

I don’t use NERDTree myself, but reading the documentation it looks like you want the s map, which opens the selected file in a new vertical split. You may also need to add set splitright to your .vimrc to ensure that the split is created at the right of the NERDTree window.

Keep in mind though that as your layouts get more complex your workflow may suffer. Here is an alternative that always work in a predictable way

| improve this answer | |

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.