2

I am working with a new old code base where virtually all the interesting source files are three levels deep in the directory hierarchy. It's about 1.3M lines of code in more than 2000 .cpp files. The project Makefile is set up so that when a compiler error happens, only the file name part of the file in question is shown, rather than the path to that file.

What I'd like to do is be able to ask vim to open a file by name only, and have it look through the directory tree to find that name for me.

I already have a tags file set up so I can jump to identifiers without caring which directory or source file name they're in, but that doesn't help for actual file names themselves.

Is there a native vim way, or a plugin, that can help with this? My ideal solution would be something that would modify the :n command so that:

  • If a path is provided (even just ./), the behaviour is unchanged;
  • If only a file name is provided, and a file by that name doesn't exist in the current directory, vim would search through the whole tree under the current directory looking for a file by that name. If one is found, open that.

A solution that uses a different command than :n would be fine.

7

You can do this by setting the 'path' option to include **, and then using the :find command:

:set path=.,,**
:find filename.cpp

The section on File Searching in the documentation describes how the ** path wildcard works.

1

CtrlP should help you. Once you set it up, it is as simple as pressing Ctrl + P (or you can have custom mapping) and typing(or pasting) the name of file.

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.