2

I am using perl.

When I press gf while having the cursor on Testcase, it shows

E447: Can't find file "Testcase.pm" in path. 

So I added that path.

It works for files under particular path which are set in :set path. I have several libraries under subdirectories of lib folder. /project/tester/userid/SCOPE/infra/lib is the path.

But when I give all the paths, gf is able to find it. Is there a way to include all subdirectories of a path recursively or making it work for all subdirectories even with the given path?

This will help me to go to any library file without needing to know the path or greping every time. There are more than 100 such files.

EDIT: Setting like set path=$PROJ/lib/** doesn't work in .vimrc and plugins too. But when I give this command in current script file, it works. My .vimrc is under /home/userid

nobe4
  • 16,033
  • 4
  • 48
  • 81
SibiCoder
  • 3,372
  • 5
  • 20
  • 40

2 Answers2

8

You can add ** to your path:

set path+=**

This way it will find every file recursively based on your current directory. But apparently it's not recommended.

If you want to add other paths, you can just add them as follow:

set path+=/path/to/your/lib
set path+=c:/include
nobe4
  • 16,033
  • 4
  • 48
  • 81
  • I tried this. :set path+=$PROJ/** . PROJ variable has our project's generic path like /project/trees/aaaa/aaaa/lib. But it didn't work. Match is a module deep under lib folder. But it doesn't recognize it. When I give this in command line of the current file, it works. But when I give it in my plugin. It doesnt recognize. – SibiCoder Apr 21 '16 at 09:29
  • 1
    I got it working here with a similar command, can you provide more details in your question? – nobe4 Apr 21 '16 at 09:47
  • May I know why the set command works when I give in current file and not in .vimrc or plugin? Can the system/project admin restrict me to add additional path here? – SibiCoder Apr 21 '16 at 09:57
  • After setting path in .vimrc, I came to script and checked set path command. It doesn't shoe the path I added. – SibiCoder Apr 21 '16 at 09:59
  • 1
  • I moved vimrc file to other name, moved all plugins out of .vim folder to some other folder. Created a new vimrc file with this line alone. When I checked in the same vimrc file by giving set path in command line, it shows the added path. I closed vim and came again. But in script, it doesn't show. Only when I give the path in script, I am Able to use. – SibiCoder Apr 21 '16 at 10:23
  • I'm not sure I understand... What do you mean by I closed vim and came again. But in script, it doesn't show. Only when I give the path in script, I am Able to use. ? – nobe4 Apr 21 '16 at 10:41
  • 3
    @SibiCoder :verbose set path? will show you what is the last file that changed the path variable. Might be some system configuration file. – tokoyami Apr 21 '16 at 10:43
  • Yes. System config file named /usr/share/vim/vim72/ftplugin.vim has changed the path. Is there a solution to override this in vimrc? – SibiCoder Apr 21 '16 at 10:46
  • 2
    The fast way is to use the after directory the following way: Create a file named ~/.vim/after/ftplugin.vim and put your path changes there. This file will get loaded after the system one. I'm pretty sure there is a better way of using the after directory for this but I cannot remember at the moment. – tokoyami Apr 21 '16 at 11:22
  • 1
    I ended up learning quite a lot as a result of that twitter link. Thank you. – Joe May 02 '20 at 15:51
3

Another alternative is to use a plugin for file search that automatically adds all directories in your project. I like to use the CtrlP plugin to navigate to files in my project. I open file under cursor by <Leader>gf. You will need this in your vimrc

" Leader gf copies word under cursor to ctrlp
nmap <leader>gf :CtrlP<CR><C-\>w
muru
  • 24,838
  • 8
  • 82
  • 143