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.
findfile()vimhelp.appspot.com/eval.txt.html#findfile%28%29). If it really needs to overwrite the
:ncommand this may help: vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev. However I would use something like this github.com/junegunn/fzf it is not exactly the solution to your
:ncommand, but in my experience this changes (improves) your whole vim workflow and you don't need that stuff. But my experience is quite limited, so maybe have a look at it, but don't let me dictate your workflow =)