Skip to content

Latest commit

 

History

History
89 lines (67 loc) · 2.46 KB

README.md

File metadata and controls

89 lines (67 loc) · 2.46 KB

go-client

pkg.go.dev Github Actions codecov.io

Neovim/go-client is a Neovim client and plugin host for Go.

This example plugin adds the Hello command to Nvim.

package main

import (
    "strings"
    "github.com/neovim/go-client/nvim/plugin"
)

func hello(args []string) (string, error) {
    return "Hello " + strings.Join(args, " "), nil
}

func main() {
    plugin.Main(func(p *plugin.Plugin) error {
        p.HandleFunction(&plugin.FunctionOptions{Name: "Hello"}, hello)
            return nil
    })
}

Build the program with the go tool to an executable named hello. Ensure that the executable is in a directory in the PATH environment variable.

// Use the `go build` command to generate an executable.
// To ensure this "hello" executable is on your path,
// you can move "hello" to your $GOPATH/bin directory
// or add the current directory to the `PATH` environment variable.
go build -o hello

Add the following plugin to Nvim:

if exists('g:loaded_hello')
    finish
endif
let g:loaded_hello = 1

function! s:Requirehello(host) abort
    " 'hello' is the binary created by compiling the program above.
    return jobstart(['hello'], {'rpc': v:true})
endfunction

call remote#host#Register('hello', 'x', function('s:Requirehello'))
" The following lines are generated by running the program
" command line flag --manifest hello
call remote#host#RegisterPlugin('hello', '0', [
    \ {'type': 'function', 'name': 'Hello', 'sync': 1, 'opts': {}},
    \ ])

" vim:ts=4:sw=4:et

Start Nvim and run the following command:

:echo Hello('world')

Release

Follow the standard Go process for publishing a module.

License

Apache License 2.0