Hello, world with goda.vim: writing Vim plugins in Go
goda.vim is a new project by Shougo that makes it possible to write Vim plugins in Go; the article walks through building a Hello, world plugin with it and positions goda.vim as a spiritual successor to denops.vim[1], a framework for writing Vim plugins in Deno. It works like denops: Vim launches an external process that speaks msgpack-rpc[2], and data is exchanged in both directions between Vim and that process. goda ships a Vim plugin and a Go package; a program written with the SDK becomes a CLI that goda.vim starts, so the Go program works as a plugin.
On the Go side, a plugin is a struct that satisfies the Plugin interface with Name() and Handlers(); handlers are called from Vim via goda#request, which corresponds to denops.dispatcher. Calls from Go to Vim go through the Host interface: Call runs a function synchronously, Notify asynchronously, Eval evaluates Vim script, and Cmd runs an ex command[3]. Values passed from Vim arrive in params []any, so existence checks and type assertions must be written by hand. goda has no automatic start mechanism, so plugins call goda#start themselves; the sample wraps it in goda_hello#start, which skips an already running process, while goda-cmp.vim starts on the VimEnter event.
Because the Go code must be compiled before use, Nix can build the plugin together with the Go binary and manage it declaratively, giving reproducible builds even when CGo[4] is involved. With denops, Deno fetches dependencies at runtime, which made Nix packaging difficult, whereas goda's use of Go makes it easier; nix run github:comamoca/goda-hello launches Vim with the example plugin. Ports of existing Shougo projects such as ddu.vim to goda are reportedly on the way.
Sources
-
JPZenn JA
【最速解説】goda.vimでHello, worldする


