admin管理员组

文章数量:1301592

I heard that one of the advantages of NeoVim is a more flexible plugin architecture. Is there an API for writing plugins in JS?

There are some projects which seem to be related to this: neovim/node-host, neovim/node-client, fritzy/node-neovim, rhysd/promised-neovim-client but I'm not sure how to use them. How do I access Vim functions or mands, or equivalent functionality (and where is this documented)?


promised-neovim-client interacts with a NeoVim process by attaching to its stdin and stdout. So maybe from within NeoVim, I could start a promised-neovim-client script and pass it the pid of the running NeoVim process and the script could attach to its stdin and stdout?

I heard that one of the advantages of NeoVim is a more flexible plugin architecture. Is there an API for writing plugins in JS?

There are some projects which seem to be related to this: neovim/node-host, neovim/node-client, fritzy/node-neovim, rhysd/promised-neovim-client but I'm not sure how to use them. How do I access Vim functions or mands, or equivalent functionality (and where is this documented)?


promised-neovim-client interacts with a NeoVim process by attaching to its stdin and stdout. So maybe from within NeoVim, I could start a promised-neovim-client script and pass it the pid of the running NeoVim process and the script could attach to its stdin and stdout?

Share edited Dec 15, 2016 at 19:28 Andrew asked Dec 3, 2016 at 2:28 AndrewAndrew 1,0741 gold badge16 silver badges27 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 9
  1. Install the node-client
    • npm install -g neovim
    • Run :checkhealth to confirm.
  2. From the quickstart, paste the sample code (below) into rplugin/node/index.js somewhere on your Nvim runtimepath (e.g. ~/.config/nvim/rplugin/node/index.js).
  3. Run :UpdateRemotePlugins.
  4. Restart Nvim.
  5. Try the :SetMyLine mand (which was defined in the above code sample).

Sample code

function onBufWrite() {
  console.log('Buffer written!');
}

module.exports = (plugin) => {
  function setLine() {
    plugin.nvim.setLine('A line, for your troubles');
  }
  plugin.registerCommand('SetMyLine', [plugin.nvim.buffer, setLine]);
  plugin.registerAutocmd('BufWritePre', onBufWrite, { pattern: '*' });
};

You can definitely write neovim plugins in javascript. From https://github./neovim/neovim/blob/master/runtime/doc/remote_plugin.txt#L7

Extensibility is a primary goal of Nvim. Any programming language may be used
to extend Nvim without changes to Nvim itself. This is achieved with remote plugins, coprocesses that have a direct munication channel (via |RPC|) with
the Nvim process.

Even though these plugins run in separate processes they can call, be called,
and receive events just as if the plugin's code were executed in the main process.

You just gotta talk to remote api

A Neovim remote plugin (rplugin) is any program that talks to nvim through the remote API (which can be reached via any arbitrary transport mechanism: TCP address, named pipe, stdin/stdout, ...).

I also couldn't find the remote API documentation. There was some examples in neovim/node-client.

Could you also take a look in to this file

本文标签: nodejsHow can I write a NeoVim plugin with JavaScriptStack Overflow