How to search a collapsed file item in NERDTree vim plugin?

7,783

The filename is not present in NERDTree's buffer so /pattern won't work. You'll have to use other tools to reach your goal.

If the file is in a directory that is part of Vim's path you can use :find like that:

:find filename
:find fil<Tab>
:find pattern

See :help path for how to add directories.

You can also do :e /path/to/directory<Tab>.

Using ** you can force Vim to look into subdirectories as well:

:e /path/**/user<Tab>

will allow you to choose from a list of all files starting with user. That's pretty neat.

If Vim's working directory is the directory of the current buffer (that's not automatic, see :help autochdir), something like

:e ../../**/*.json

would bring a list of all JSON files in your project. Well, I don't know how your project is laid out but you get the picture.

See :help file-searching for a detailed explanation.


Alternatively, you could use a plugin. CtrlP is a nice and powerful "fuzzy" file-naviation plugin that does one thing that I find super useful: when invoked, it looks up and up until it finds a VCS "marker" (a .git directory, for example) and uses it a starting point for your search. This makes opening files in the current project almost "fun".

Share:
7,783

Related videos on Youtube

Benjamin
Author by

Benjamin

직장인들을 위한 소개팅 서비스 커피한잔을 개발, 운영하고 있습니다.

Updated on September 18, 2022

Comments

  • Benjamin
    Benjamin over 1 year

    NERDTree is my best vim plugin. To find a file or directory item, I move to my cursor to tree view, and use /. But I still don't know how to find a file item which be in collapsed(closed) tree. NERDTree does not support this? How do you do find a file?