Rhinosaurus
Rhinosaurus

Reputation: 1284

Find command in vim gets incomplete path

In vim when I'm using :find to open another file, it misses the first component of the relative path.

For example, if I'm looking for a file that's in:

./foo/bar/file.txt

I'll type

:find **/file.txt

It finds the file but then tries to open

bar/file.txt

It works correctly if I type

./**/file.txt

But I'm lazy and don't want to type that much. Is there some config I'm missing that will correctly locate and open this path?

My Solution

I simply appended the main source code dir to my path

exec "set path^=src/**"

Upvotes: 1

Views: 136

Answers (1)

dash-tom-bang
dash-tom-bang

Reputation: 17843

Is your 'path' set? That (IMO) is a pretty handy way to keep from even typing the **/ bit.

In my setup, there's an environment variable that defines which project I'm currently in so I use that and construct a path with that as the root. In a nutshell:

let s:rootdir = $PROJECT_DIR
let s:path = 'src/**;' . s:rootdir . ',scripts/**;' . s:rootdir
execute "set path=" . s:path

Then I can just :find a_file.txt and it searches my src hierarchy then my scripts hierarchy for the file.

Upvotes: 2

Related Questions