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.
Currently in my tests I don’t use relative paths to the source code, but instead module name and path, like:
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.
Put it in vimfiles/after/after/ftplugin/ and it will do the trick.