Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/denops_std/mod.ts

๐Ÿ“š Standard module for denops.vim
Latest
import * as denopsStd from "https://deno.land/x/denops_std@v6.5.1/mod.ts";

Standard module for denops.vim.

This module is assumed to be used for developing denops plugins. The code is assumed to be called in a dedicated worker thread.

By using this module, developers can write Vim/Neovim denops plugins like:

import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.1/mod.ts";
import * as batch from "https://deno.land/x/denops_std@v6.5.1/batch/mod.ts";
import * as fn from "https://deno.land/x/denops_std@v6.5.1/function/mod.ts";
import * as vars from "https://deno.land/x/denops_std@v6.5.1/variable/mod.ts";
import * as helper from "https://deno.land/x/denops_std@v6.5.1/helper/mod.ts";

import { assert, is } from "https://deno.land/x/unknownutil@v3.14.1/mod.ts";

export const main: Entrypoint = async (denops) => {
  denops.dispatcher = {
    async init() {
      // This is just an example. Developers usually should define commands directly in Vim script.
      await batch.batch(denops, async (denops) => {
        await denops.cmd(
          `command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])`,
        );
        await denops.cmd(
          `command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])`,
        );
      });
    },
    async say(where) {
      assert(where, is.String);
      const [name, progname] = await batch.collect(denops, (denops) => [
        fn.input(denops, "Your name: "),
        vars.v.get(denops, "progname"),
      ]);
      const messages = [
        `Hello ${where}.`,
        `Your name is ${name}.`,
        `This is ${progname}.`,
      ];
      await helper.echo(denops, messages.join("\n"));
    },
  };
};

Note that developers should avoid calling initialization code within the main function. If necessary, add an init API or a similar approach like above and call it from plugin/<your_plugin>.vim.

See Denops Documentation or denops-helloworld.vim for more details.

Classes

Batch error raised when one of the functions fails during batch process.

Interfaces

Denops is a facade instance visible from each denops plugin.

Environment meta information.

Type Aliases

Context that expands into the local namespace (l:)

API dispatcher

Denops's entrypoint definition.