I just learned of vim’s gf command for navigating to files that are referenced in other files, such as c includes. I’m wanting to get this working within the Yii php framework, where files can be registered with the autoloader like this:
Yii::import('path.to.ClassName', true);
Using gf on ClassName has no effect because it’s not the real file path. However, it would be easy enough to translate it to the file path, which is path/to/ClassName.php.
Furthermore, there are other mechanisms within Yii that utilize path aliases, such as begining a widget, which looks like this:
$this->beginWidget('ext.widgets.widgetName.ClassName');
Where ext.widgets.widgetName.ClassName is an alias to somewhere, perhaps protected/extensions/widgets/widgetName/ClassName.php. In this case the alias ext is expanded to its full path at runtime, so vim cannot know the full file path.
Is there a way to overload/remap gf so within a php project it could either:
- calculate the correct file path, then go to the file, or if file not found then
- perform a tag lookup of
ClassName?
See
:help includeexpr. The example listed there for Java might suit your purposes:More generally, see
:help gfand then follow the jumps to the settings that control it (like I just did :).