import { autocmd } from "https://deno.land/x/ddc_vim@v4.0.2/deps.ts";
const { group } = autocmd;
Create an autocmd group and define/remove autocmds in that group.
import { Denops } from "../mod.ts";
import { group } from "./group.ts";
export async function main(denops: Denops): Promise<void> {
await group(denops, "my-autocmd", (helper) => {
// Define new autocmd for BufEnter
helper.define("BufEnter", "*", "echo 'BufEnter'");
// Define new autocmd for BufEnter with '++once'
helper.define("BufEnter", "*", "echo 'BufEnter'", {
once: true,
});
// Define new autocmd for BufEnter with '++nested'
helper.define("BufEnter", "*", "echo 'BufEnter'", {
nested: true,
});
// Define multiple autocmds
helper.define(["BufEnter", "WinEnter"], "*", "echo 'Enter'");
// Remove BufEnter autocmd
helper.remove("BufEnter", "*");
// Remove any autocmd in buffer
helper.remove("*", "<buffer>");
// Remove multiple autocmds
helper.remove(["BufEnter", "WinEnter"], "*");
});
}
This is preferable way to define autocmd while it define autocmds in an isolated autocmd group and the number of RPC calls is minimized.