Giter Club home page Giter Club logo

vim-node's Introduction

Node.vim

Build status

Tools to make Vim superb for developing with Node.js.
It's the Node equivalent of Rails.vim (vimscript #1567) and Rake.vim (vimscript #3669).

This is just the first release to get the nodes rolling. If you've collected great helpers and shortcuts that help you work with Node, please share them via email, Twitter or GitHub issues so we could incorporate them here, too! Thanks!

Tour

  • Use gf on paths or requires to open the same file Node.js would.
  • Use gf on require(".") to open ./index.js
  • Use gf on require("./dir") to open ./dir/index.js
  • Use gf on require("./foo") to open foo.js.
  • Use gf on require("./package") and have it open package.json.
  • Use gf on require("module") to open the module's main file (parsed for you from package.json).
  • Use gf on require("module/lib/utils") and open files inside the module.
  • Automatically sets the filetype to JavaScript for files with Node's shebang (#!).
  • Use [I etc. to look for a keyword in required files (Sets Vim's &include).
  • Use :Nedit to quickly edit any module, file in a module or your project file.
  • Use :Nopen to quickly edit any module and lcd to its directory.
  • Lets you even open Node's core modules. They're shown straight from Node's online repository without you having to download everything.
  • Node.vim itself is tested with a thorough automated integration test suite! No cowboy coding here!

Expect more to come soon and feel free to let me know what you're after!

PS. Node.vim is absolutely intended to work on Windows, but not yet tested there at all. If you could help, try it out and report issues, I'd be grateful!

Installing

The easiest and most modular way is to download this to ~/.vim/bundle:

mkdir -p ~/.vim/bundle/node

Using Git:

git clone https://github.com/moll/vim-node.git ~/.vim/bundle/node

Using Wget:

wget https://github.com/moll/vim-node/archive/master.tar.gz -O- | tar -xf- --strip-components 1 -C ~/.vim/bundle/node

Then prepend that directory to Vim's &runtimepath (or use Pathogen):

:set runtimepath^=~/.vim/bundle/node

Vundle

Or use Vundle:

:BundleInstall moll/vim-node

Using

Open any JavaScript file inside a Node project and you're all set.

  • Use gf inside require("...") to jump to source and module files.
  • Use [I on any keyword to look for it in the current and required files.
  • Use :Nedit module_name to edit the main file of a module.
  • Use :Nedit module_name/lib/foo to edit its lib/foo.js file.
  • Use :Nedit . to edit your Node projects main (usually index.js) file.

Want to customize settings for files inside a Node projects?

Use the Node autocommand. For example:

autocmd User Node if &filetype == "javascript" | setlocal expandtab | endif

Want <C-w>f to open the file under the cursor in a new vertical split?

<C-w>f by default opens it in a horizontal split. To have it open vertically, drop this in your vimrc:

autocmd User Node
  \ if &filetype == "javascript" |
  \   nmap <buffer> <C-w>f <Plug>NodeVSplitGotoFile |
  \   nmap <buffer> <C-w><C-f> <Plug>NodeVSplitGotoFile |
  \ endif

Viewing Node.js core modules

Open Vim in the directory of a Node.js project and use :Nedit with the name of the core module:

:Nedit http

This downloads a single file from the Node.js repository for your Node version through https://rawgit.com. If you'd like to change the base URL, set g:node_repository_url:

let node_repository_url = "https://example.com/nodejs/node"

License

Node.vim is released under a Lesser GNU Affero General Public License, which in summary means:

  • You can use this program for no cost.
  • You can use this program for both personal and commercial reasons.
  • You do not have to share your own program's code which uses this program.
  • You have to share modifications (e.g bug-fixes) you've made to this program.

For more convoluted language, see the LICENSE file.

About

Andri Möll authored this in SublemacslipseMate++.
Monday Calendar supported the engineering work.

If you find Node.vim needs improving or you've got a question, please don't hesitate to email me anytime at [email protected], tweet at @theml or create an issue online.

vim-node's People

Contributors

dweinstein avatar jalcine avatar moll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-node's Issues

Can't remap keys

I apologize in advance for my ignorance, I'm just a vim newb. This plugin looks really awesome, and I'd like to use it to view the source code of node modules.

I'm using a slightly modified version for yadr for my dotfiles, and the gf keybinding is clashing with something there. So I did the following:

  • I added autocmd User Node nnoremap <buffer> ,nf <Plug>NodeGotoFile to my vimrc
  • Did :source $MYVIMRC
  • Did :map ,nf ... got o , YRMapsExpression("<SNR>192_", ",") (which I think is irrelevant, I had it before)
  • Opened a node file, put my cursor on the 'n' of 'net' inside the require in var net = require('net');
  • Did ,nf ... got E486: Pattern not found: plug

Am I not doing this remapping correctly? Also, does this module not expose vim commands like :NodeGotoFile so I can call it without a keybinding?

Jump to matched file

When I press [I on a keyword, I get a few matches in another window.

screenshot 2016-01-14 12 54 32

How can I jump to the second match? Since each match has a number label, I assume I can jump to the second match by pressing 2. But it doesn't work, it just simply close the window.

Open path in new tab

Hello! Thank you for great work! Is this possible to open modules by "gf" or "[I" in new tab? That would be very handy.

Support opening scoped requires (@scope/foo)

Hello,

I've been using Node.vim for quite some time now. Thanks for making it! </voice-in-my-head>

Anywho, why doesn't it support opening require("@moll/foo") with gf yet?

It must!

Shortcut for installing npm package `require()`

It would be nice to install npm packages within vim.
E.g.

var foo = require('body-parser');

When I press the shortcut anywhere on this line, it would execute npm install --save body-parser.

Would that be possible and doable?

:Nopen for built-ins doesn't work for io.js

Just thought you'd know that using Nopen for bulitns (eg :Nopen fs) doesn't work for io.js. It'll try to look for the file for node v2.5.0 (or whatever version you're on).

Make opened modules read-only by default

To me, it makes a lot of sense to make some modules open in read-only when opened by gf or :Nedit and the like. It doesn't make much sense to be able to edit the fs module, which is a standard module.

On the other hand, it makes more sense to be allowed to edit locally downloaded modules. The distinction of course can be easily made, since standard modules such as fs must be curled, while local modules are found locally. So the same logic could be used to set readonly and set nomodifiable.

Pressing `gf` on require("./directory") should open ./directory/index.js

Indeed, my split personality self. That's because we're currently depending on Vim's built-in includeexpr to get a chance to look up the required file and Vim thinks it can handle that relative path to an existing directory itself.

Don't yet know how to get it to pass existing directories onward to us without Vim opening them by default.

goto project-local definition?

I'm not sure how they do it, but in golang-vim, you can hover over a function call, type "gd", and it will take you to the file and line of the definition of that function within your go module. Since nodejs has a similar project-root boundary (package.json), I think it would be a big win if vim-node could provide something similar.

Using gf, etc, for AMD module paths.

Hi, I like the idea of being able to use gf to open files from the path in the text, but it'd be nice if this worked for other package systems like AMD, etc.

I've got this:

/**
 * @fileoverview Defines the unit details sub-app
 */
define([
  'js/mpq/subapps/base',
  'js/mpq/layouts/results/unit-details'
],
function(SubApp, Layout) {
  return SubApp.extend({

    Layout: Layout,

    navigation: true

  });
});

If I put my cursor on 'js/mpq/layouts/results/unit-details' then I get an error:

E447: Can't find file "js/mpq/layouts/results/unit-details" in path

Obviously this is because it's not a Node.js module, and the js folder is actually ../../../js.

Is there a way to configure paths for a project so if it doesn't find the file, it can check the path list or similar? Maybe something like

let g:pathsOrWhatever = ['$HOME/src/project/', '/absolute/path', './etc']

and it could be saved in the project folder and I could source it.

This could also work with typescript

I want to say how awesome this is, worked pretty well!. Also it kinda work with typescript, but only for absolute paths.

The example bellow on a typescript file works:

 import {foo} from './foo/bar';

but, The example bellow on a typescript file does not work:

 import {foo} from 'foo/dist/bar';

Travis is broken

This is a follow up to the discussion on #31. Travis currently has errors during the installation process. I saw some improved results (but still some build errors) by using this yaml file:

language: ruby
rvm:
  - 2.1.3

before_install:
  - sudo apt-get update -qq
  - sudo apt-get install -y vim-gtk
install: bundle install --deployment --without development
before_script:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
script: xvfb-run make test

The apt-get commands are the main thing that made a difference (it seemed to be able to find the vim-gtk package this way). The error I saw looked like this:

$ sudo apt-get update -qq
$ sudo apt-get install -y vim-gtk
...
$ bundle install --deployment --without development
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/moll/vimrunner.git
Using minitest 4.7.5
NoMethodError: undefined method `spec' for nil:NilClass
An error occurred while installing
vimrunner (0.3.0), and Bundler cannot
continue.
Make sure that `gem install vimrunner -v
'0.3.0'` succeeds before bundling.

The command "bundle install --deployment --without development" failed and exited with 5 during .

Your build has been stopped.

:A (Alternate) support

It would be nice to use colon A to toggle between alternate files like you can in Rails.vim

it should process more smartly 'gf' on dirs

I think when we pressing gf on a 'somePath' which is a directory itself and contains 'index.js' file, which in turn contains only one line like export { default } from './somePath' it should open it instead of 'index.js

Cannot goto netrw file

Using goto file command (gf in normal mode) under a netrw file (like "http://github.com") will give an error "E447: Can't find file ... in path" instead of trying to fetch the file

Feature request: ES2015 module resolution support

I was looking for a plugin that would let me use gf with both node require() and ES2015 import syntax; this plugin solved 3 of 4 situations:

  • ✔ Relative Node modules: const someModule = require('./someModule')
  • ✔ Resolved Node modules: const someModule = require('someModule')
  • ✔ Relative ES2015 modules: import someModule from './someModule'
  • 🙏 Resolved ES2015 modules: import someModule from 'someModule'

Because ES2015 modules are gaining greater popularity and are being considered for Node itself, it would be awesome if this plugin covered the fourth situation as well. To go along with this, this plugin could potentially be re-named to vim-es-modules or something...

p.s. Great plugin! Thank you for making it :)

work with typescript

It's pretty plugin, and how should I use it work with ts?

It's just like

Use gf on paths or requires to open the same file Typescript would.

gf on require() of core modules

Hi,

New to vim-node so forgive me if I'm misusing or have misconfigured something.

I'm hitting 'gf' on a require("fs") statement. It's navigating to the core fs module but does two things I'm not expecting:

  1. Fetching the file over curl a-new each time (even if I've just navigated to it a few moments ago). I'm sometimes offline, so some reasonable caching defaults (or local-db fallback option) would be good -- not to mention, internet speeds are fast but non-zero.
  2. The opened module is replacing the existing buffer -- my natural instinct of hitting ':q' to return closes everything out. I could use ':e#' but I think we should be going back to the previous buffer by default on ':q'?

Thanks,
Phil

Open in new window split

Is there any way that vim-node could have a command to open the file in a new vertical/horizontal split? Maybe vgf or hgf? A new tab would probably be helpful as well... tgf

Add a help file

It'd be nice if we could add a docs/ folder with documentation that's accessible from within vim via :h. @moll have you thought about adding this?

I know there a few utilities out there for auto-generating documentation from comments (which are really easy to use, in my experience). If you'd be interested, I could try a PR using Google's vimdoc package.

"E121: Undefined variable: b:node_root" error

First of all, thanks for sharing this nice plugin!

When issuing Ctrl+p/n or [+I on some files (which ends with .js) I get the following error:

    E121: Undefined variable: b:node_root
    Error detected while processing function node#lib#find[8]..<SNR>233_absolutize:
    line    7:
    E15: Invalid expression: b:node_root . "/node_modules/" . a:name  

The variable b:node_root is indeed undefined on the files which display errors. On the files where the problem doesn't ocurr the variable is defined.

vim-node README.md install instructions update

https://github.com/moll/vim-node
README.md

Using Wget:
wget https://github.com/moll/vim-node/archive/master.tar.gz -O- | tar -xf- --strip-components 1 -C ~/.vim/bundle/node

  1. Requires tar's -z option (tar -x -z -f ) to gunzip the tar.gz file.
  2. Readability recommendation only, add space between wget -O option and stdout (-).
  3. Readability recommendation only, add space between tar -f option and stdin (-).

Using long options:
wget --output-document=- https://github.com/moll/vim-node/archive/master.tar.gz | tar --extract --gunzip --strip-components 1 --file=- --directory=~/.vim/bundle/node
OR
Using short options:
wget -O - https://github.com/moll/vim-node/archive/master.tar.gz | tar --strip-components 1 -xzf - -C ~/.vim/bundle/node

Cheers

Support for other extensions

With the coming of ES6, as well as server-side react, there are a few more extensions that it would be good if vim-node would recognize: *.es, *.es6, *.jsx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.