Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

neovim-client

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neovim-client

Neovim client library

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-26.32%
Maintainers
2
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 03 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc