Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Can't set 'path' correctly to make 'gf' work

Tags:

vim

I'm trying to get gf working with paths that look like this:

foo/bar.js

The file is located here: /Users/dimal/dev/project/src/foo/bar.js

So I set my path like this:

set path+=/Users/dimal/dev/project/src

It seems like gf should find the file but it doesn't.

E447: Can't find file "foo/bar.js" in path

Why?

I've tried other variations:

/Users/dimal/dev/project/src/**
/Users/dimal/dev/project/src/**/*
like image 233
mrdanimal Avatar asked May 26 '16 23:05

mrdanimal


1 Answers

gf commands searches for files in the paths include via :set path.

set path command accepts wildcards like *. (* means any character) So, if you wanted to include all files under subdirectories of a directory, you can give

      :set path+=directory/**

For a depth of three levels under a directory, that is , to include files under any subdirectory of subdirectory of subdirectory of current directory, you can specify like directory/**3

Maximum depth allowed is 100.

A command like

       :set path+=/Users/dimal/dev/project/src/**3

will allow you to search for file named bar.js in src/subdirectory/subdirectory/subdirectory as well, not just in src/.

like image 169
SibiCoder Avatar answered Sep 19 '22 12:09

SibiCoder