Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python client and plugin host for Nvim

License

NotificationsYou must be signed in to change notification settings

neovim/pynvim

Repository files navigation

Documentation StatusCode coverage

Pynvim implements support for python plugins in Nvim. It also works as a library forconnecting to and scripting Nvim processes through its msgpack-rpc API.

Install

Supports python 3.7 or later.

  • Installation option #1: install using uv (recommended):

    • Install uv (https://docs.astral.sh/uv/).

    • Install pynvim (the--upgrade switch ensures installation of the latestversion):

      uv tool install --upgrade pynvim
    • Anytime you upgrade Neovim, make sure to upgrade pynvim as well byre-running the above command.

  • Installation option #2: install using pipx:

    • Install pipx (https://pipx.pypa.io/stable/).

    • Install pynvim (the--upgrade switch ensures installation of the latestversion):

      pipx install --upgrade pynvim
    • Anytime you upgrade Neovim, make sure to upgrade pynvim as well byre-running the above command.

  • Other installation options:

Python Plugin API

Pynvim supports pythonremote plugins (via the language-agnostic Nvim rplugininterface), as well asVim plugins (via the:python3 interface). Thus whenpynvim is installed Neovim will report support for the+python3 Vim feature.

The rplugin interface allows plugins to handle vimL function calls as well asdefining commands and autocommands, and such plugins can operate asynchronouslywithout blocking nvim. For details on the new rplugin interface,see theRemote Plugin documentation.

Pynvim defines some extensions over the vim python API:

  • Builtin and plugin vimL functions are available asnvim.funcs
  • API functions are available asvim.api and for objects such asbuffer.api
  • Lua functions can be defined usingvim.exec_lua and called withvim.lua
  • Support for thread-safety and async requests.

See thePython Plugin API documentation for usage of this new functionality.

Known Issues

  • Vim evaluates'v:<bool>' to<class 'bool'>, whereas neovim evaluates to<class 'str'>. This is expected behaviour due to the way booleans are implemented in python as explainedhere.

Development

Use (and activate) a local virtualenv, for example:

python3 -m virtualenv venvsource venv/bin/activate

If you change the code, you must reinstall for the changes to take effect:

pip install .

Usepytest to run the tests. Invoking withpython -m prepends the currentdirectory tosys.path (otherwisepytest might find other versions!):

python -m pytest

For details about testing and troubleshooting, see thedevelopmentdocumentation.

Usage from the Python REPL

A number of different transports are supported, but the simplest way to getstarted is with the python REPL. First, start Nvim with a known address:

$ nvim --listen /tmp/nvim.sock

Or alternatively, note thev:servername address of a running Nvim instance.

In another terminal, connect a python REPL to Nvim (note that the API is similarto the one exposed by thepython-vimbridge):

>>>importpynvim# Create a session attached to Nvim's address (`v:servername`).>>>nvim=pynvim.attach('socket',path='/tmp/nvim.sock')# Now do some work.>>>buffer=nvim.current.buffer# Get the current buffer>>>buffer[0]='replace first line'>>>buffer[:]= ['replace whole buffer']>>>nvim.command('vsplit')>>>nvim.windows[1].width=10>>>nvim.vars['global_var']= [1,2,3]>>>nvim.eval('g:global_var')[1,2,3]

You can embed Neovim into your python application instead of connecting toa running Neovim instance.

>>>importpynvim>>>nvim=pynvim.attach('child',argv=["/usr/bin/env","nvim","--embed","--headless"])
  • The--headless argument tellsnvim not to wait for a UI to connect.
  • Alternatively, use--embedwithout--headless if your client is a UIand you wantnvim to wait for your client tonvim_ui_attach beforecontinuing startup.

See thetests for more examples.

Release

  1. Create a release commit with titlePynvim x.y.z
    • list significant changes in the commit message
    • bump the version inpynvim/_version.py
  2. Push tomaster.
    git push
  3. Make a release on GitHub with the same commit/version tag and copy the message.
  4. Runscripts/disable_log_statements.sh
  5. Runpipx run build
  6. (Validation) Diff the release tarballdist/pynvim-x.y.z.tar.gz against the previous one.
  7. Runpipx run twine upload -r pypi dist/*
    • Assumes you have a pypi account with permissions.
  8. Runscripts/enable_log_statements.sh orgit reset --hard to restore the working dir.
  9. Bump up to the next development version inpynvim/_version.py, withprerelease suffixdev0.

Releasing with bump-my-version

bump-my-version automates the process of updating version strings, creating git commits, and tagging releases.

  1. Installbump-my-version:If you haven't already, install the development dependencies:

    pip install .[dev]
  2. Bump the version:To increment the version, use one of the following commands:

    • Patch release:bump-my-version bump patch (e.g.,0.6.1 ->0.6.2)
    • Minor release:bump-my-version bump minor (e.g.,0.6.1 ->0.7.0)
    • Major release:bump-my-version bump major (e.g.,0.6.1 ->1.0.0)

    This command will:

    • Update theversion inpyproject.toml.
    • Update theVERSION inpynvim/_version.py.
    • Create a git commit with a message like "Bump version: 0.6.1 → 0.6.2".
    • Create a git tag (e.g.,v0.6.2).
  3. Push changes and tags:After bumping the version, push the commit and the new tag to your remote repository:

    git push --follow-tags

License

Apache License 2.0


[8]ページ先頭

©2009-2025 Movatter.jp