0

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

4

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
  • 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 9:29
  • 1
    I got it working here with a similar command, can you provide more details in your question? – nobe4 Apr 21 '16 at 9:47
  • 1
    Maybe it's an issue in your vimrc. – nobe4 Apr 21 '16 at 10:00
  • 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
  • 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
2

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

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.