Coder Social home page Coder Social logo

nvim-yarp's Introduction

Yet Another Remote Plugin Framework for Neovim

This is my attempt on writing a remote plugin framework without :UpdateRemotePlugins.

Requirements

  • has('python3')
  • For Vim 8:
    • roxma/vim-hug-neovim-rpc
    • g:python3_host_prog pointed to your python3 executable, or echo exepath('python3') is not empty.
    • pynvim (pip3 install pynvim)

Use case

Usage

pythonx/hello.py

import vim, time
def greet():
    time.sleep(3)
    vim.command('echo "Hello world"')

plugin/hello.vim

" Create a python3 process running the hello module. The process is lazy load.
let s:hello = yarp#py3('hello')

com HelloSync call s:hello.request('greet')
com HelloAsync call s:hello.notify('greet')

" You could type :Hello greet
com -nargs=1 Hello call s:hello.request(<f-args>)

Debugging

Add logging settigns to your vimrc. Log files will be generated with prefix /tmp/nvim_log. An alternative is to export environment variables before starting vim/nvim.

let $NVIM_PYTHON_LOG_FILE="/tmp/nvim_log"
let $NVIM_PYTHON_LOG_LEVEL="DEBUG"

Example for existing neovim rplugin porting to Vim 8

More realistic examples could be found at nvim-typescript#84, deoplete#553, callmekohei/quickdebug.

Now let's consider the following simple rplugin.

After UpdateRemotePlugins and restarting neovim, you get foobar by :echo Bar().

# rplugin/python3/foo.py
import pynvim

@pynvim.plugin
class Foo(object):

    def __init__(self, vim):
        self._vim = vim

    @pynvim.function("Bar", sync=True)
    def bar(self, args):
        return 'hello' + str(args)

For working on Vim 8, you need to add these two files:

" plugin/foo.vim
if has('nvim')
    finish
endif

let s:foo = yarp#py3('foo_wrap')

func! Bar(v)
    return s:foo.call('bar',a:v)
endfunc
# pythonx/foo_wrap.py
from foo import Foo as _Foo
import vim

_obj = _Foo(vim)


def bar(*args):
    return _obj.bar(args)

How to use

$ vim

: echo bar('world')

hello('world',)

nvim-yarp's People

Contributors

callmekohei avatar roxma avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

sonvt1710

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.