typescript与neovim
neovim的主流语言是lua,但是我的lua环境没有配置好,也更倾向于外部工具的交互而非内部的文本处理,所以就想用nodejs来作为接口(python虽然功能可能更强,但是我机子慢,不适合python
)
github上有模板,下载下来放在.config/nvim下面就行了。
import { NvimPlugin } from 'neovim';
export default function myplugin(plugin: NvimPlugin) {
plugin.setOptions({
// Set your plugin to dev mode, which will cause the module to be reloaded on each invocation
dev: true,
// `alwaysInit` will always attempt to attempt to re-instantiate the
// plugin. e.g. your plugin class will always get called on each invocation
// of your plugin's command.
alwaysInit: false,
});
plugin.registerCommand(
'EchoMessage',
async () => {
try {
await plugin.nvim.outWrite('Dayman (ah-ah-ah) \n');
} catch (err) {
console.error(err);
}
},
{ sync: false },
);
plugin.registerFunction(
'SetLines',
async () => {
await plugin.nvim
.setLine('May I offer you an egg in these troubling times');
},
{ sync: false },
);
}
尤其要注意的一点是尽量使用await,别用promise,会提示报错。