
Show HN: Vim gf-command improved - koomenk
Since a week ago I remembered myself of the awesome gf-command in Vim, which allows you to open the current filepath under the cursor in a new buffer. I thought to myself: <i>Why am I never using this? Oh yeah, because this only works for filepaths relative to the buffer</i>. As a javascript developer most of my time, that won’t help since I have webpack-configured projects which allows me to do some super cool absolute imports, but throws away the complete usage of the awesome gf-command.<p>So I started a Vim plugin called <i>gfi</i> (goto file improved). The goal for me was to create a plugin that is plug ’n play, zero-configuration required for you to enjoy this simple but efficient plugin.<p>So how does it work? When using this plugin your regular <i>gf</i> will be remapped and when pressing <i>gf</i> it always tries to resolve the file under the cursor using atleast the following logic:<p>- relative to the current buffer<p>- relative to Vim&#x27;s current working directory<p>- based on the git directory it is located in<p>Implementing these 3 checks for every filetype made sense to me. Just having these 3 checks already makes gf already much more efficient want useful.<p>If these 3 fail to retrieve a path then some filetypes may have additional checks. Javascript-like projects can be webpack-configured and thus may use absolute imports. These are done by checking the package.json in the root of the project.<p>Golang path resolving for the import-statement is also taken into account. Since these imports are directories, the directory will be opened rather than a file, but it’s still more efficient, since <i>gf</i> does not open directories by default.<p>A goal I have is hoping for contributions for as many languages as possible so that the <i>gf</i> command will be more useful for many more developers.<p>If you have feedback or like to contribute, send me a mail or do your contribution via <a href="https:&#x2F;&#x2F;github.com&#x2F;kkoomen&#x2F;gfi.vim" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kkoomen&#x2F;gfi.vim</a>
======
psophis
What's the difference between this and a properly setup file type plugin? As
here [0] with python lets you open imported modules using `gf`.

[0]:
[https://github.com/vim/vim/blob/a87b72cc316e065d66dcbcf7ec1c...](https://github.com/vim/vim/blob/a87b72cc316e065d66dcbcf7ec1cde330adef3a3/runtime/ftplugin/python.vim#L30)

~~~
koomenk
Another thing I just tested using “includeexpr”, “path” and “suffixesadd” is
that it is not possible (as far as my knowledge goes) to let vim open files
correctly if the import path is a directory. Which my module does very well
for javascript-like projects.

