sran.nvim
Simple Request And Notification script for (neo)vim
Last updated 9 months ago by yuuko .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sran.nvim 
SYNC missed versions from official npm registry.

Simple Request And Notification

The easiest way to write remote plugin for (neo)vim by javascript

Using neovim's node-client you can write remote plugin really easy through javascript. But most of time i just want to run an async function to fetch some data or other stuff, and sran.nvim is for the situation and also support vim by vim-node-rpc.

Install

It works on vim >= 8.1 and neovim

" use pre build
Plug 'iamcco/sran.nvim', { 'do': { -> sran#util#install() } }

" use node.js and yarn
Plug 'iamcco/sran.nvim', { 'do': 'yarn' }

Hello world

plugin structure

your-plugin-dir
  -> rplugin
     -> sran
        -> hello-world.js // or javascript dir package

hello-world.js

module.exports = function (plugin) {
  const nvim = plugin.nvim
  nvim.on('notification', (method, args) => {
    if (method === 'hello_world') {
      setTimeout(() => {
        nvim.command('echo "hello world"')
      }, 2000)
    }
  })
}

install sran.nvim and your plugin

Plug 'iamcco/sran.nvim', { 'do': { -> sran#util#install() } }
Plug 'your-account/your-plugin-name'

now

:call sran#rpc#notify('hello_world')

then you will see hello world message in the command line after 2 seconds.

use request for sync

About

  • sran.nvim will use builtin node.js binary if use pre build
  • builtin packages
    • fast-glob
    • log4js
    • msgpack-lite
    • neovim
    • node-fetch
    • tslib
    • cheerio
    • rxjs
    • findup

    so if you use these packages you don't need to install them in your plugin's local directory

  • javascript Plugin api
    • nvim vim instance
    • util
      • getIP: function to get ip
      • opener: it's opener fork to opens stuff, like webpages and files and executables, cross-platform
      • getLogger: function to get log4js's logger instance
  • viml api
    • sran#rpc#notify for notification call
    • sran#rpc#request for request call

Examples

Debug

let $NVIM_SRAN_LOG_FILE = expand('~/sran-nvim.log')
let $NVIM_SRAN_LOG_LEVEL = 'debug'

Buy Me A Coffee ☕️

btc

image

Current Tags

  • 0.0.6                                ...           latest (9 months ago)

5 Versions

  • 0.0.6                                ...           9 months ago
  • 0.0.5                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (9)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |