Skip to content

Commit 97f6bae

Browse files
committed
📝 Update README
1 parent d06b9b5 commit 97f6bae

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,41 @@ for a plugin.
1313
By using this module, developers can write Vim/Neovim denops plugins like:
1414

1515
```typescript
16-
import { ensureString, main } from "https://deno.land/x/denops_std/mod.ts";
16+
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
17+
import { execute } from "https://deno.land/x/denops_std/helper/mod.ts";
18+
import { ensureString } from "https://deno.land/x/unknownutil/mod.ts";
1719

18-
main(async ({ vim }) => {
19-
vim.register({
20+
export async function main(denops: Denops): Promise<void> {
21+
denops.dispatcher = {
2022
async say(where: unknown): Promise<void> {
21-
ensureString(where, "where");
22-
const name = await vim.call("input", "Your name: ");
23-
const progname = await vim.eval("v:progname");
23+
// Ensure that `where` is `string` here
24+
ensureString(where);
25+
// Use `call` to call Vim's function
26+
const name = await denops.call("input", "Your name: ");
27+
// Use `eval` to evaluate Vim's expression
28+
const progname = await denops.eval("v:progname");
29+
// Construct messages
2430
const messages = [
2531
`Hello ${where}`,
2632
`Your name is ${name}`,
2733
`This is ${progname}`,
2834
];
29-
await vim.cmd(`redraw | echomsg message`, {
35+
// Use `cmd` to execute Vim's command
36+
await denops.cmd(`redraw | echomsg message`, {
3037
message: messages.join(". "),
3138
});
3239
},
33-
});
34-
35-
await vim.execute(`
36-
command! HelloWorld call denops#notify("${vim.name}", "say", ["World"])
37-
command! HelloDenops call denops#notify("${vim.name}", "say", ["Denops"])
38-
`);
39-
40-
console.log("denops plugin has loaded");
41-
});
40+
};
41+
42+
// Use 'execute()' to execute multiline Vim script
43+
await execute(
44+
denops,
45+
`
46+
command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])
47+
command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])
48+
`,
49+
);
50+
}
4251
```
4352

4453
See [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)

0 commit comments

Comments
 (0)