Skip to content

Instantly share code, notes, and snippets.

@latentflip
Last active April 14, 2021 03:29
Show Gist options
  • Save latentflip/57bf8f9edde531ee979e to your computer and use it in GitHub Desktop.
Save latentflip/57bf8f9edde531ee979e to your computer and use it in GitHub Desktop.
vim, gf, and node

Vim, gf and node.

So, I just learned that gf exists. If your cursor is over a path in vim, and you type gf, it'll open that file/dir in a new buffer. You can also open in a new window/tab as detailed here.

In node, it'd be great if you could jump to a required file, huh? Trouble is, typically you don't put the .js on your require('./path/to/a/js/file'). No matter, vim has your back, just add set suffixesadd+=.js to your .vimrc and vim will try adding .js and see if it can find that file instead.

If you do a lot of spelunking in node_modules, it'd be great if you could jump to the directory of a required npm module too, right? A la, require('my-awesome-module'). Well, you can add set path+=$PWD/node_modules to your .vimrc too, and vim will add node_modules to the path, and jump to it's directory in node_modules (caveat: you must have opened vim from your project root for this too work).

For your cmd+c convenience:

set suffixesadd+=.js
set path+=$PWD/node_modules
@voischev
Copy link

voischev commented Apr 8, 2021

for me set path+=**

@bumaociyuan
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment