3 Neovim API
The Neovim API is exposed through an object-oriented interface in Racket. A Neovim instance is represented as an instance of the nvim% class, and its buffers, windows and tab pages are represented as instances of the buffer%, window% and tabpage% classes respectively. Global API calls are implemented as methods of nvim%, and API calls to buffers, windows and tab pages are implemented as methods of their respective classes.
As a general rule, method names are the same as the API function names, except that underscores (_) have been replaced by hyphens (-), the prefixes (e.g. nvim_ or nvim_buf_) have been stripped away and API calls returning a boolean value (predicates) have a question mark (?) appended. For example, nvim_buf_is_valid becomes is-valid?, and instead of providing a buffer ID as the first argument the method is sent to the buffer object in question.
You do not instantiate API object from their constructors directly, they are returned to you by functions like nvim-attach or methods of other API objects like get-current-buf.
; Attach to a Neovim instance and keep the return value (define nvim (nvim-attach in out)) ; Get a reference to the current buffer (define current-buf (send nvim get-current-buf)) ; Set the name of the current buffer (send current-buf set-name "Main Buffer")
Should an object become invalid (e.g. the window% handle of a window that has been closed), sending it a message will result in an RPC error.
All API methods can be called in a synchronous (blocking) or asynchronous (non-blocking) way by providing the optional #:async keyword argument. The default is always asynchronous. Asynchronous calls never return a value, so calling a pure getter method makes little sense, but it is technically possible.
3.1 Classes
If a method is lacking documentation please refer to the Neovim API reference (:h api) for details. There is no point in repeating the same thing here as well.
Perform a raw RPC request with procedure name method and procedure argument param. The result is whatever the remote procedure returns back over the connection. Blocks until a result is returned.In practice you should not have to call this method yourself, use the API methods instead. They have the proper signature, take a fixed number of arguments and specify more accurate contracts.
Similar to request, except no value is returned and execution does not block after the RPC message has been sent off.Execute the ex-command cmd.
method
(send a-nvim get-hl-by-name name rgb? [ #:async async?]) → hash? name : string? rgb? : boolean? async? : boolean? = #f Gets a highlight definition by name. If rgb? is true, then the colour is an RGB value.
method
(send a-nvim get-hl-by-id id rgb? [ #:async async?]) → hash? id : integer? rgb? : boolean? async? : boolean? = #f Gets a highlight definition by id. If rgb? is true, then the colour is an RGB value.
method
(send a-nvim feedkeys keys mode escape-csi? [ #:async async?]) → void keys : string? mode : string? escape-csi? : boolean? async? : boolean? = #f
method
(send a-nvim replace-termcodes str from-part? do-lt? special? [ #:async async?]) → string? str : string? from-part? : boolean? do-lt? : boolean? special? : boolean? async? : boolean? = #f
method
(send a-nvim command-output str [ #:async async?]) → string? str : string? async? : boolean? = #f
method
(send a-nvim call-function fname args [ #:async async?]) → packable? fname : string? args : (vector packable?) async? : boolean? = #f
method
(send a-nvim execute-lua code args [ #:async async?]) → packable? code : string? args : (vector packable?) async? : boolean? = #f
method
(send a-nvim list-runtime-paths [#:async async?])
→ (vectorof string?) async? : boolean? = #f
method
(send a-nvim set-current-dir dir [ #:async async?]) → void dir : string? async? : boolean? = #f
method
(send a-nvim get-current-dir [#:async async?]) → string?
async? : boolean? = #f
method
(send a-nvim set-current-line line [ #:async async?]) → void line : string? async? : boolean? = #f
method
(send a-nvim get-current-line [#:async async?]) → string?
async? : boolean? = #f
method
(send a-nvim del-current-line [#:async async?]) → void
async? : boolean? = #f
method
(send a-nvim set-var name value [ #:async async?]) → void name : string? value : packable? async? : boolean? = #f
method
(send a-nvim set-option name value [ #:async async?]) → void name : string? value : packable? async? : boolean? = #f
method
(send a-nvim get-option name [ #:async async?]) → packable? name : string? async? : boolean? = #f
method
(send a-nvim err-writeln str [ #:async async?]) → void str : string? async? : boolean? = #f
method
→ (vectorof (instanceof/c buffer%)) async? : boolean? = #f
method
(send a-nvim get-current-buf [#:async async?])
→ (instanceof/c buffer%) async? : boolean? = #f
method
(send a-nvim set-current-buf buffer) → void
buffer : (instanceof/c buffer% [#:async async? boolean? #f])
method
→ (vectorof (instanceof/c window%)) async? : boolean? = #f
method
(send a-nvim get-current-win [#:async async?])
→ (instanceof/c window%) async? : boolean? = #f
method
(send a-nvim set-current-win window) → void
window : (instanceof/c window% [#:async async? boolean? #f])
method
(send a-nvim list-tabpages [#:async async?])
→ (vectorof (instanceof/c tabpage%)) async? : boolean? = #f
method
(send a-nvim get-current-tabpage [#:async async?])
→ (instanceof/c tabpage%) async? : boolean? = #f
method
(send a-nvim set-current-tabpage tabpage) → void
tabpage : (instanceof/c tabpage% [#:async async? boolean? #f])
method
(send a-nvim unsubscribe event [ #:async async?]) → void event : string? async? : boolean? = #f
method
(send a-nvim get-color-by-name name [ #:async async?]) → integer? name : string? async? : boolean? = #f
method
(send a-nvim get-color-map [#:async async?]) → hash?
async? : boolean? = #f
method
(send a-nvim get-keymap mode [ #:async async?]) → (vectorof hash?) mode : string? async? : boolean? = #f
method
(send a-nvim get-api-info [#:async async?]) → vector?
async? : boolean? = #f
method
(send a-nvim call-atomic calls [ #:async async?]) → vector? calls : vector? async? : boolean? = #f
method
(send a-nvim ui-attach width height options [ #:async async?]) → void width : integer? height : integer? options : hash? async? : boolean? = #f
| ||
superclass: object% | ||
|
method
(send a-buffer get-lines start end strict-indexing? [ #:async async?]) → (vectorof string?) start : integer? end : integer? strict-indexing? : boolean? async? : boolean? = #f
method
(send a-buffer set-lines start end strict-indexing? replacement [ #:async async?]) → void start : integer? end : integer? strict-indexing? : boolean? replacement : string? async? : boolean? = #f
method
(send a-buffer set-var name value [ #:async async?]) → void name : string? value : packable? async? : boolean? = #f
method
(send a-buffer get-keymap mode [ #:async async?]) → (vectorof hash?) mode : string? async? : boolean? = #f
method
(send a-buffer get-option name [ #:async async?]) → packable? name : string? async? : boolean? = #f
method
(send a-buffer set-option name value [ #:async async?]) → void name : string? value : packable? async? : boolean? = #f
method
(send a-buffer get-mark name [ #:async async?]) → (vector/c integer? integer? #:flat #t #:immutable #t) name : string? async? : boolean? = #f
| ||
superclass: object% | ||
|
method
(send a-window get-cursor [#:async async?])
→ (vector/c integer? integer? #:flat #t #:immutable #t) async? : boolean? = #f
method
(send a-window set-height height [ #:async async?]) → void height : integer? async? : boolean? = #f
method
(send a-window set-width width [ #:async async?]) → void width : integer? async? : boolean? = #f
method
(send a-window set-var name value [ #:async async?]) → void name : string? value : packable? async? : boolean? = #f
method
(send a-window get-option name [ #:async async?]) → packable? name : string? async? : boolean? = #f
method
(send a-window set-option name value [ #:async async?]) → void name : string? value : packable? async? : boolean? = #f
| ||
superclass: object% | ||
|
method
(send a-tabpage list-windows [#:async async?])
→ (vectorof (is-a?/c window%)) async? : boolean? = #f Returns a vector of window% objects contained in a-tabpage.Returns the current window in a-tabpage.Returns the tab page nuber of a-tabpage.Returns the value of the tab-local variable name in a-tabpage.
method
(send a-tabpage set-var name value [ #:async async?]) → void name : string? value : any/c async? : boolean? = #f Sets the value of the tab-local variable name in a-tabpage.Deletes the value of the tab-local variable name in a-tabpage.Checks whether a-tabpage is valid.