Go to file under the cursor in Vim
Let's say in a file you reference another one, requiring that code. Vim has an very easy way to open the required (imported, loaded, etc) file. Great tip for adding external dependencies code.
Put the cursor in the file name you want to open and:
gf
If you want to go back: <Ctrl> o
.
To find the file Vim uses an option called path
, and you can check your current path with:
:set path
So if you expect a file is not being found you can check the path
and add values to it.
:set path+=some_special_folder/
Finally, as Vim looks for a lot of paths, it may find more than one, and gf
will bring the first one. To get the second match, type g2f
, for the third g3f
and so on.
Also, check this article to restrict Vim options by file extensions and to add file suffixes.
Tweet