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.
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
:Neditto 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.