|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/neovim/python-client)
|
4 | 4 |
|
5 |
| -Library aims to emulate the current python-vim interface through Neovim |
6 |
| -msgpack-rpc API |
| 5 | +Library for scripting Nvim processes through it's msgpack-rpc API. |
7 | 6 |
|
8 | 7 | #### Installation
|
9 | 8 |
|
10 | 9 | ```sh
|
11 | 10 | pip install neovim
|
12 | 11 | ```
|
13 | 12 |
|
14 |
| -#### Usage |
| 13 | +#### Usage through the python REPL |
15 | 14 |
|
16 |
| -Start Neovim with a known address or query the value of $NVIM_LISTEN_ADDRESS |
17 |
| -after startup: |
| 15 | +A number of different transports are supported, but the simplest way to get |
| 16 | +started is with the python REPL. First, start Nvim with a known address(or |
| 17 | +query the value of $NVIM_LISTEN_ADDRESS of a running instance): |
18 | 18 |
|
19 | 19 | ```sh
|
20 |
| -$ NVIM_LISTEN_ADDRESS=/tmp/neovim nvim |
| 20 | +$ NVIM_LISTEN_ADDRESS=/tmp/nvim nvim |
21 | 21 | ```
|
22 | 22 |
|
23 |
| -Open the python REPL with another terminal connect to Neovim: |
| 23 | +Open the python REPL with another terminal connect to Nvim(Note that the API is |
| 24 | +similar to the one exposed by the [python-vim |
| 25 | +bridge](http://vimdoc.sourceforge.net/htmldoc/if_pyth.html#python-vim)) |
24 | 26 |
|
25 | 27 | ```python
|
26 |
| ->>> import neovim |
27 |
| ->>> vim = neovim.connect('/tmp/neovim') |
28 |
| ->>> buffer = vim.buffers[0] # get the first buffer |
| 28 | +>>> from neovim import socket_session, Nvim |
| 29 | +# Create a msgpack-rpc session to the unix domain socket created by Nvim: |
| 30 | +>>> session = socket_session('/tmp/nvim') |
| 31 | +# Create a Nvim instance from the session(don't call Nvim constructor!): |
| 32 | +>>> nvim = Nvim.from_session(session) |
| 33 | +# Now do some work. |
| 34 | +>>> buffer = nvim.buffers[0] # Get the first buffer |
29 | 35 | >>> buffer[0] = 'replace first line'
|
30 | 36 | >>> buffer[:] = ['replace whole buffer']
|
31 |
| ->>> vim.command('vsplit') |
32 |
| ->>> vim.windows[1].width = 10 |
33 |
| ->>> vim.vars['global_var'] = [1, 2, 3] |
34 |
| ->>> vim.eval('g:global_var') |
| 37 | +>>> nvim.command('vsplit') |
| 38 | +>>> nvim.windows[1].width = 10 |
| 39 | +>>> nvim.vars['global_var'] = [1, 2, 3] |
| 40 | +>>> nvim.eval('g:global_var') |
35 | 41 | [1, 2, 3]
|
36 | 42 | ```
|
37 | 43 |
|
38 |
| -See the test subdirectory for more examples |
39 |
| - |
40 |
| -This is still alpha and incomplete, use only for testing purposes |
| 44 | +The tests can be consulted for more examples. |
0 commit comments