FazJaxton
FazJaxton

Reputation: 7904

Supply a path for file editing in VIM?

Is there a way to set a PATH-like sequence of directories to search for files in vim? My project has C files split across many directories, and it would be nice to jump back and forth without remembering the full path each time.

For instance, if I have:

platform/drivers/uart.c
ui/display/menu.c
cpu/registers/regs.h

I would like to be able to set PATH to "platform/drivers:ui/display:cpu/registers". Then when I want to switch to a file, I can just type:

:e uart.c

instead of

:e platform/drivers/uart.c

I understand that I can change the working directory, but then I have to type

:e ../../ui/display/menu.c

to get to another directory.

Alternatively, is there a better way to navigate a project like this than using :edit?

Upvotes: 1

Views: 83

Answers (1)

Joni
Joni

Reputation: 111219

There is, and it's called path. The way you use path is with the :find command: :find menu.c would search for menu.c in the directories in path and edit it. There are other commands that use path, like :sfind that opens the found file in a new split. See the documentation of path for details and other commands that use it.

Another thing that may help you find your files is the **-wildcard that can expand to any directory path. For example :edit **/menu.c will look for menu.c in subdirectories, so you don't have remember and type the full path.

Upvotes: 3

Related Questions