11 09 2013
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.
Some interesting aspects of “call” method in JavaScript Using = null; instead of ;
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.