3

I am trying to setup my development environment using vim and some plugins.

My workspace root is a directory with very large number of sub-directories and files. I am going to be working on files from a very very small subset of this root directory.

For a simplified overview,

  • My workspace root directory ($workspace) contains 1000+ different projects (sub-dirs with lot of sources files, tools and docs)
  • I am working on max 4-5 "projects" inside this workspace at a time.

All version control, build and run commands are run at the $workspace root directory. Hence, I want to keep the vim open with its CWD as the workspace root.

I want to use plug-ins such as NerdTree and Ctrl-P, etc. These plugins usually work at a CWD level and try to index/cache contents of the entire $workspace. So, direct usage of them is causing my file navigation to be impossibly slow.

I want to set-up a white-listing system (a file called .project or something) at the $workspace root that lists all the directories that I am interested in. I need vim and its plugins to only index or parse the contents of these very few sub-directories.

I could not find a turn-key solution that achieves this. I am willing to write some code to make this work. Any ideas and suggestions are most welcome.

0

2 Answers 2

2

It is possible using the dirvish file explorer, which by the way is much faster than the native netrw.

This plugin allows to manipulate the content of its buffer (see "How do I filter" in :h dirvish-faq) and has an option to automatically execute a command. Keep in mind that it operates on the full path and directories have trailing slashes, so to keep everything starting with "a" or ending with "z":

let g:dirvish_mode = ':silent keeppatterns g!/a[^/]*\/$\|.*z\/$/d _'

In this example, :global! is used to reverse the search and d to delete the matching lines. The patterns are not thoroughly tested but it seems to work:

  • a[^/]*\/$ looks for "a" followed by anything but a slash before the last "/"
  • \| OR
  • .*z\/$ looks for anything ending with "z/"

See How to load different .vimrc file for different working directory? to set this option based on the current working directory (but you might want it only if the opened directory matches the CWD).

Finally, take a look at the end of this answer about editing large projects and how to optimize ctrlp.

1

I think you should be able to achieve this by using the 'wildignore' option.

set wildignore+=*/ignoredir1/**/*,*/ignoredir2/**/*,*/ignoredir3/**/*

CtrlP respects this by default, and NERDTree will if you tell it to in your .vimrc:

let NERDTreeRespectWildIgnore=1

Unfortunately, this isn't a whitelist, so you will need to manually add in all the things you want to ignore.

If this is impractical, because the contents of your CWD are too numerous or frequently changing, there's no reason you couldn't set it programmatically in a loop, using glob() to get a list of directory contents, isdirectory() to check if each path is a directory, and using set wildignore+= to append anything that isn't in your whitelist to the option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.