Skip to content

Commit 4abd5d0

Browse files
committed
readme: update docs about api methods
1 parent 5d40785 commit 4abd5d0

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ below.
4646
```
4747
vim.funcs.setreg('0', ["some", "text"], 'l')
4848
```
49+
50+
* `vim.api` exposes nvim API methods. For instance to call `nvim_strwidth`,
51+
```
52+
result = vim.api.strwidth("some text")
53+
```
54+
Note the initial `nvim_` is not included. Also, object methods can be called
55+
directly on their object,
56+
```
57+
buf = vim.current.buffer
58+
len = buf.api.line_count()
59+
```
60+
calls `nvim_buf_line_count`. Alternatively msgpack requests can be invoked
61+
directly,
62+
```
63+
result = vim.request("nvim_strwith", "some text")
64+
len = vim.request("nvim_buf_line_count", buf)
65+
```
66+
4967
* The API is not thread-safe in general. However, `vim.async_call` allows a
5068
spawned thread to schedule code to be executed on the main thread. This method
5169
could also be called from `:python` or a synchronous request handler, to defer
@@ -59,9 +77,9 @@ below.
5977
process), and `vim.async_call` can be used to send results back to nvim.
6078

6179
* Some methods accept an `async` keyword argument: `vim.eval`,
62-
`vim.command` as well as the `vim.funcs` wrappers. The python host will not
63-
wait for nvim to complete the request (which also means that the return value
64-
is unavailable).
80+
`vim.command`, `vim.request` as well as the `vim.funcs` and `vim.api` wrappers.
81+
The python host will not wait for nvim to complete the request (which also
82+
means that the return value is unavailable).
6583

6684
#### Remote (new-style) plugins
6785

0 commit comments

Comments
 (0)