package module
v0.0.0-...-32a96bf Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2016 License: MIT Imports: 15 Imported by: 1


vim-go-client - Vim 8.0 client written in go

Travis Build Status Coverage Status Go Report Card LICENSE GoDoc


🐦 Author

haya14busa (



Package vim provides Vim client and server implementations. You can start Vim as a server as a child process or connect to Vim, and communicate with it via TCP or stdin/stdout. :h channel.txt




This section is empty.


View Source
var ErrExpr = errors.New("the evaluation fails or the result can't be encoded in JSON")

ErrExpr represents "expr" command error.

View Source
var ErrTimeOut = errors.New("time out")

ErrTimeOut represents time out error.


func NewChildClient

func NewChildClient(handler Handler, args []string) (*Client, *ChildCliCloser, error)

NewChildClient creates connected child process Vim client.

func NewReadWriter

func NewReadWriter(r io.Reader, w io.Writer) io.ReadWriter

NewReadWriter returns simple io.ReadWriter. bufio.ReadWriter has buffers and needs to be flushed., so we cannot use bufio.NewReadWriter() for Vim client which accept io.ReadWriter. ref:!topic/golang-nuts/OJnnwlfsPCc

func SetLogger

func SetLogger(l *log.Logger)

SetLogger sets the logger that is used in go process. Call only from init() functions.


type Body

type Body interface{}

Body represents Message body. e.g. {expr} of `:h ch_sendexpr()`

type ChildCliCloser

type ChildCliCloser struct {
	// contains filtered or unexported fields

ChildCliCloser is closer of child Vim client process.

func (*ChildCliCloser) Close

func (c *ChildCliCloser) Close() error

Close closes child Vim client process.

type Client

type Client struct {
	// contains filtered or unexported fields

Client represents Vim client.

func NewClient

func NewClient(rw io.ReadWriter, handler Handler) *Client

NewClient creates Vim client.

Example (Job)
package main

import (

	vim ""

type echoHandler struct{}

func (h *echoHandler) Serve(cli *vim.Client, msg *vim.Message) {

func main() {
	// see example/echo/ for working example.
	handler := &echoHandler{}
	cli := vim.NewClient(vim.NewReadWriter(os.Stdin, os.Stdout), handler)

func (*Client) Call

func (cli *Client) Call(funcname string, args ...interface{}) (Body, error)

Call runs command "call" (:h channel-commands).

func (*Client) Ex

func (cli *Client) Ex(cmd string) error

Ex runs command "ex" (:h channel-commands).

func (*Client) Expr

func (cli *Client) Expr(expr string) (Body, error)

Expr runs command "expr" (:h channel-commands).

func (*Client) Normal

func (cli *Client) Normal(ncmd string) error

Normal runs command "normal" (:h channel-commands).

func (*Client) Redraw

func (cli *Client) Redraw(force string) error

Redraw runs command "redraw" (:h channel-commands).

func (*Client) Send

func (cli *Client) Send(msg *Message) error

Send sends message to Vim.

func (*Client) Start

func (cli *Client) Start() error

Start starts to wait message from Vim.

func (*Client) Write

func (cli *Client) Write(p []byte) (n int, err error)

Write writes raw message to Vim.

type Handler

type Handler interface {
	Serve(*Client, *Message)

Handler represents go server handler to handle message from Vim.

type Message

type Message struct {
	MsgID int
	Body  Body

Message represents rpc message type of JSON channel. `:h channel-use`.

type Process

type Process struct {
	// contains filtered or unexported fields

Process represents Vim server process.

func NewChildVimServer

func NewChildVimServer(addr string, args []string) (*Process, error)

NewChildVimServer creates Vim server process and connect to go-server by addr.

func (*Process) Close

func (p *Process) Close() error

Close closes Vim process.

type Server

type Server struct {
	Handler Handler // handler to invoke

Server represents go server.

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Serve starts go server.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL