typescript与neovim

neovim 的主流语言是 lua,但是我的 lua 环境没有配置好,也更倾向于外部工具的交互而非内部的文本处理,所以就想用 nodejs 来作为接口(python 虽然功能可能更强,但是我机子慢,不适合 python:sob: :joy:

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, 会提示报错。