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 02 Answers
Reset to default 9- Install the node-client
npm install -g neovim
- Run
:checkhealth
to confirm.
- 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
). - Run
:UpdateRemotePlugins
. - Restart Nvim.
- 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
版权声明:本文标题:node.js - How can I write a NeoVim plugin with JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741676744a2391924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论