@@ -13,32 +13,41 @@ for a plugin.
13
13
By using this module, developers can write Vim/Neovim denops plugins like:
14
14
15
15
``` 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" ;
17
19
18
- main ( async ({ vim }) = > {
19
- vim . register ( {
20
+ export async function main( denops : Denops ) : Promise < void > {
21
+ denops . dispatcher = {
20
22
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
24
30
const messages = [
25
31
` Hello ${where } ` ,
26
32
` Your name is ${name } ` ,
27
33
` This is ${progname } ` ,
28
34
];
29
- await vim .cmd (` redraw | echomsg message ` , {
35
+ // Use `cmd` to execute Vim's command
36
+ await denops .cmd (` redraw | echomsg message ` , {
30
37
message: messages .join (" . " ),
31
38
});
32
39
},
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
+ }
42
51
```
43
52
44
53
See [ denops-helloworld.vim] ( https://github.com/vim-denops/denops-helloworld.vim )
0 commit comments