vim-go-client: github.com/haya14busa/vim-go-client Index | Examples | Files

package vim

import "github.com/haya14busa/vim-go-client"

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

Index

Examples

Package Files

io.go logger.go server.go vimclient.go vimserver.go

Variables

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

ErrExpr represents "expr" command error.

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

ErrTimeOut represents time out error.

func NewReadWriter Uses

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: https://groups.google.com/forum/#!topic/golang-nuts/OJnnwlfsPCc

func SetLogger Uses

func SetLogger(l *log.Logger)

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

type Body Uses

type Body interface{}

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

type ChildCliCloser Uses

type ChildCliCloser struct {
    // contains filtered or unexported fields
}

ChildCliCloser is closer of child Vim client process.

func (*ChildCliCloser) Close Uses

func (c *ChildCliCloser) Close() error

Close closes child Vim client process.

type Client Uses

type Client struct {
    // contains filtered or unexported fields
}

Client represents Vim client.

func NewChildClient Uses

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

NewChildClient creates connected child process Vim client.

func NewClient Uses

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

NewClient creates Vim client.

Code:

package main

import (
    "os"

    vim "github.com/haya14busa/vim-go-client"
)

type echoHandler struct{}

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

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

func (*Client) Call Uses

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

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

func (*Client) Ex Uses

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

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

func (*Client) Expr Uses

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

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

func (*Client) Normal Uses

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

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

func (*Client) Redraw Uses

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

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

func (*Client) Send Uses

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

Send sends message to Vim.

func (*Client) Start Uses

func (cli *Client) Start() error

Start starts to wait message from Vim.

func (*Client) Write Uses

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

Write writes raw message to Vim.

type Handler Uses

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

Handler represents go server handler to handle message from Vim.

type Message Uses

type Message struct {
    MsgID int
    Body  Body
}

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

type Process Uses

type Process struct {
    // contains filtered or unexported fields
}

Process represents Vim server process.

func NewChildVimServer Uses

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

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

func (*Process) Close Uses

func (p *Process) Close() error

Close closes Vim process.

type Server Uses

type Server struct {
    Handler Handler // handler to invoke
}

Server represents go server.

func (*Server) Serve Uses

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

Serve starts go server.

Package vim imports 15 packages (graph) and is imported by 1 packages. Updated 2016-09-30. Refresh now. Tools for package owners.