1- import { Context , Denops , Dispatcher } from "./deps.ts" ;
1+ import { Context , Denops , Dispatcher , getCacheOrElse } from ". ./deps.ts" ;
22import { execute } from "./execute.ts" ;
33import { autocmd , AutocmdHelper } from "./autocmd.ts" ;
44import { VariableHelper } from "./variable.ts" ;
@@ -23,6 +23,12 @@ export class Vim {
2323 this . env = new VariableHelper ( denops , "env" ) ;
2424 }
2525
26+ static get ( ) : Vim {
27+ return getCacheOrElse ( "vim" , ( ) => {
28+ return new Vim ( Denops . get ( ) ) ;
29+ } ) ;
30+ }
31+
2632 get name ( ) : string {
2733 return this . #denops. name ;
2834 }
@@ -39,8 +45,11 @@ export class Vim {
3945 return await this . #denops. eval ( expr , context ) ;
4046 }
4147
42- async execute ( command : string | string [ ] ) : Promise < void > {
43- await execute ( this . #denops, command ) ;
48+ async execute (
49+ command : string | string [ ] ,
50+ context : Context = { } ,
51+ ) : Promise < void > {
52+ await execute ( this . #denops, command , context ) ;
4453 }
4554
4655 async autocmd (
@@ -56,8 +65,5 @@ export class Vim {
5665}
5766
5867export function start ( main : ( vim : Vim ) => Promise < void > ) {
59- Denops . start ( async ( denops ) => {
60- const vim = new Vim ( denops ) ;
61- await main ( vim ) ;
62- } ) ;
68+ Denops . start ( ( ) => main ( Vim . get ( ) ) ) ;
6369}
0 commit comments