Notes of Maks Nemisj

Experiments with JavaScript

Vim script for Node.js and ‘gf’

I wrote a vim script which can help you to do ‘gf’ on require statements when coding node.js modules. It uses node.js module resolution algorithm to add all the node_modules folders into the vim path variable, so that you can do ‘gf’ on modules which are not relative to the current folder of the file. Which means that doing ‘gf’ on require(‘express’) will open folder of the express source code.

Why.
Currently in my tests I don’t use relative paths to the source code, but instead module name and path, like:

require('my-module/lib/some-unit-to-test.js');

so that I don’t have a path dependency of the test relative to the source code. This script helps me to jump into the source code from the test file. Might be useful for other people who also do vim and node.js.

https://raw.github.com/nemisj/vimfiles/master/local-config/after/ftplugin/javascript.vim

Put it in vimfiles/after/after/ftplugin/ and it will do the trick.

, ,

One thought on “Vim script for Node.js and ‘gf’

  • Andri Möll says:

    Hey,

    Seems we’re both after the same things! 🙂 I started something alike back in July to make general Node.js development on Vim more convenient — Node.vim. It also features some other capabilities like :Nedit to open files inside the Node project (incl. core modules). Let me know how it fits your work and if you get thoughts what else it should do.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.