If you spend any amount of time on Reddit or YouTube — which I emphatically advise against — you will find that the topic of LSPs is a horse so thoroughly beaten that it is practically pleading for you to deliver it a coup de grâce. I allude to it here only to make reference to the obvious consensus that it is desirable to be able to navigate between files referenced from your buffers.

Much to the dismay of many Vim users, gf does not provide you with a girlfriend, it instead loads the contents of the path under your cursor. By default, your search path for the file in question is relative to your cwd. You can check your cwd via :pwd and update it via :cd, if you want to see your current path use :set path. If you have references to files that live outside of your cwd, you can add them to your path with :set path+=/home/carson/code/go/example/.

This can be useful if you are referencing some local Go packages stored outside of your project, or in some relative TypeScript import setup that gets rebuilt by your bundler such as import foobar from 'src/foobar.ts' with a path like /home/carson/code/ts/ipsum/frontend/src/foobar.ts where your cwd is ipsum. In this case you can run :set path+=frontend and it will do the trick.

Thanks to our ol’ pal netrw, the path variable also supports including URLs which can be pretty nifty if you want to navigate through a website (a good website that is, not one that pulls in 50 npm packages just to add a date picker).

Reference: If you are unfamiliar with the power of netrw consider reading neat-rw

For those following along with today’s lesson,

  1. :set path=.,https://blog.nerdware.ca
  2. :set includeexpr=substitute(v:fname,'^/','','')
  3. Put your cursor over https://blog.nerdware.ca

    Hint: Before you jump around in the next step, know that you can come back to this buffer with <C-o>

  4. Hit gf and now notice that the anchor tags are navigable for you by invoking gf on them.

    Note: The reason we need that substitute command in step 2 is because the anchor tags are absolutely referenced.

I bet you that reading this blog through Vim would actually be a rather pleasant experience. If you have Lynx installed then you can open it in Vim, and then replace your buffer’s contents with Lynxy magic via :%!lynx -dump -stdin.

Mnemonic

This one is almost too easy via “Go to File”.

insert meme of George Costanza holding the bat