npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

neovim-client

v2.1.0

Published

Neovim client library

Downloads

38

Readme

neovim-client

Build Status

Installation

npm install --global neovim-client

Usage

This package exports a single attach() function which takes a pair of write/read streams and invokes a callback with a Nvim API object. This is similar to node-msgpack5rpc, but it provides an automatically generated API.

Additionally, a Promise-based API may be obtained using require('neovim-client/promise').

Examples:

var cp = require('child_process'),
    attach = require('neovim-client'),
    nvim_proc = cp.spawn('nvim', ['-u', 'NONE', '-N', '--embed'], {})

attach(nvim_proc.stdin, nvim_proc.stdout, function(err, nvim) {

  nvim.on('request', function(method, args, resp) {
    // handle msgpack-rpc request
  })

  nvim.on('notification', function(method, args) {
    // handle msgpack-rpc notification
  })

  nvim.command('vsp', function(err, res) {
    nvim.getWindows(function(err, windows) {
      console.log(windows.length)  // 2
      console.log(windows[0] instanceof nvim.Window) // true
      console.log(windows[1] instanceof nvim.Window) // true
      nvim.setCurrentWindow(windows[1], function(err, res) {
        nvim.getCurrentWindow(function(err, win) {
          console.log(win.equals(windows[1]))  // true
          nvim.quit()
          nvim.on('disconnect', function() {
            console.log("Nvim exited!")
          })
        })
      })
    })
  })
})

or, using Promises:

var cp = require('child_process'),
    attach = require('neovim-client/promise'),
    nvim_proc = cp.spawn('nvim', ['-u', 'NONE', '-N', '--embed'], {}),
    nvim

attach(nvim_proc.stdin, nvim_proc.stdout)
.then(function(_nvim) {
    nvim = _nvim
    return nvim.command('vsp')
})
.then(function(res) {
    return nvim.getWindows()
})
.then(function(windows) {
    console.log(windows.length)  // 2
    console.log(windows[0] instanceof nvim.Window) // true
    console.log(windows[1] instanceof nvim.Window) // true
    return nvim.setCurrentWindow(windows[1])
    .then(function(res) {
        return nvim.getCurrentWindow()
    })
    .then(function(win) {
        console.log(win.equals(windows[1]))
        nvim.on('disconnect', function() {
            console.log("Nvim exited!")
        })
        nvim.quit()
    })
})
.catch(function(err) {
    console.error(err)
    nvim.quit()
})

Methods are attached to buffers, windows and tabpages according to the msgpack-rpc name:

nvim.getCurrentBuffer(function(err, buf) {
  console.log(buf instanceof nvim.Buffer)  // true
  buf.getLineSlice(0, -1, true, true, function(err, lines) {
    console.log(lines)  // ['']
    buf.setLineSlice(0, -1, true, true, ['line1', 'line2'], function(err) {
      buf.getLineSlice(0, -1, true, true, function(err, lines) {
        console.log(lines)  // ['line1', 'line2']
      })
    })
  })
})

A typescript declaration file is available as documentation of the API and also for typescript users that seek to use this library. Note that the interfaces are automatically generated at a certain point in time, and may not correspond exactly to the API of your installed Nvim.