Skip to content

vim-denops/deno-denops-std

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5f8e7f4 Β· Feb 21, 2025
Aug 18, 2024
Oct 25, 2024
Aug 26, 2024
Aug 27, 2024
Jul 8, 2024
Nov 28, 2024
Aug 26, 2024
Aug 24, 2024
Nov 20, 2024
Feb 19, 2025
Aug 25, 2024
Aug 27, 2024
Sep 6, 2024
Nov 13, 2024
Jul 3, 2024
May 5, 2023
Feb 3, 2024
Jun 26, 2021
Oct 3, 2021
Aug 3, 2024
May 22, 2023
Feb 19, 2025
Jul 30, 2024

Repository files navigation

🐜 @denops/std

JSR Test codecov

Deno 1.45.0 or above Vim 9.1.0448 or above Neovim 0.10.0 or above

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 { Denops } from "jsr:@denops/std";
import * as batch from "jsr:@denops/std/batch";
import * as fn from "jsr:@denops/std/function";
import * as vars from "jsr:@denops/std/variable";
import * as helper from "jsr:@denops/std/helper";

import { assert, is } from "jsr:@core/unknownutil";

export function main(denops: Denops): void {
  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.

License

The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.