如何使用 JavaScript 编写 NeoVim 插件?
How can I write a NeoVim plugin with JavaScript?
听说 NeoVim 的优点之一是更灵活的插件架构。
有没有用JS写插件的API?
有些项目似乎与此有关:
neovim/node-host,
neovim/node-client, fritzy/node-neovim, rhysd/promised-neovim-client
但我不确定如何使用它们。
我如何访问 Vim functions 或命令,或等效功能(以及记录在何处)?
promised-neovim-client 通过附加到其标准输入和标准输出来与 NeoVim 进程交互。
所以也许在 NeoVim 中,我可以启动一个 promised-neovim-client 脚本并将 运行 NeoVim 进程的 pid 传递给它并且脚本可以附加到它的标准输入和标准输出?
你绝对可以在 javascript 中编写 neovim 插件。来自 https://github.com/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 communication 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.
你只需要和远程通话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, ...).
我也找不到远程 API 文档。 neovim/node-client
.
中有一些例子
你能不能也看看这个 file
- Install node-client
npm install -g neovim
- 运行
:checkhealth
确认。
- 从 quickstart,将示例代码(下方)粘贴到 Nvim runtimepath 上的
rplugin/node/index.js
某处(例如 ~/.config/nvim/rplugin/node/index.js
)。
- 运行
:UpdateRemotePlugins
.
- 重新启动 Nvim。
- 尝试
:SetMyLine
命令(在上面的代码示例中定义)。
示例代码
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: '*' });
};
听说 NeoVim 的优点之一是更灵活的插件架构。 有没有用JS写插件的API?
有些项目似乎与此有关: neovim/node-host, neovim/node-client, fritzy/node-neovim, rhysd/promised-neovim-client 但我不确定如何使用它们。 我如何访问 Vim functions 或命令,或等效功能(以及记录在何处)?
promised-neovim-client 通过附加到其标准输入和标准输出来与 NeoVim 进程交互。 所以也许在 NeoVim 中,我可以启动一个 promised-neovim-client 脚本并将 运行 NeoVim 进程的 pid 传递给它并且脚本可以附加到它的标准输入和标准输出?
你绝对可以在 javascript 中编写 neovim 插件。来自 https://github.com/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 communication 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.
你只需要和远程通话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, ...).
我也找不到远程 API 文档。 neovim/node-client
.
你能不能也看看这个 file
- Install node-client
npm install -g neovim
- 运行
:checkhealth
确认。
- 从 quickstart,将示例代码(下方)粘贴到 Nvim runtimepath 上的
rplugin/node/index.js
某处(例如~/.config/nvim/rplugin/node/index.js
)。 - 运行
:UpdateRemotePlugins
. - 重新启动 Nvim。
- 尝试
:SetMyLine
命令(在上面的代码示例中定义)。
示例代码
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: '*' });
};