On this page:
3.1 Classes
nvim%
request
notify
command
get-hl-by-name
get-hl-by-id
feedkeys
input
replace-termcodes
command-output
eval
call-function
execute-lua
strwidth
list-runtime-paths
set-current-dir
get-current-dir
set-current-line
get-current-line
del-current-line
set-var
get-var
del-var
get-vvar
set-option
get-option
out-write
err-write
err-writeln
list-bufs
get-current-buf
set-current-buf
list-wins
get-current-win
set-current-win
list-tabpages
get-current-tabpage
set-current-tabpage
subscribe
unsubscribe
get-color-by-name
get-color-map
get-mode
get-keymap
get-api-info
call-atomic
ui-attach
ui-detach
ui-try-resize
ui-set-option
buffer%
line-count
get-lines
set-lines
get-var
set-var
del-var
get-chagedtick
get-keymap
get-option
set-option
get-name
set-name
is-valid?
get-mark
add-highlight
clear-highlight
window%
get-buf
get-tabpage
get-cursor
get-height
set-height
get-width
set-width
get-var
set-var
del-var
get-option
set-option
get-position
get-number
is-valid?
tabpage%
list-windows
get-winow
get-number
get-var
set-var
del-var
is-valid?
7.1

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.

class

nvim% : class?

  superclass: object%

Represents a Neovim instance.

method

(send a-nvim request method param ...)  any/c

  method : string?
  param : any/c
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.

method

(send a-nvim notify method param ...)  void

  method : string?
  param : any/c
Similar to request, except no value is returned and execution does not block after the RPC message has been sent off.

method

(send a-nvim command cmd [#:async async?])  void

  cmd : string?
  async? : boolean? = #f
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 input keys [#:async async?])  integer?

  keys : string?
  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 eval expr [#:async async?])  packable?

  expr : 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 strwidth text [#:async async?])  integer?

  text : string?
  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 get-var name [#:async async?])  packable?

  name : string?
  async? : boolean? = #f

method

(send a-nvim del-var name [#:async async?])  void

  name : string?
  async? : boolean? = #f

method

(send a-nvim get-vvar name [#:async async?])  packable?

  name : string?
  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 out-write str [#:async async?])  void

  str : string?
  async? : boolean? = #f

method

(send a-nvim err-write str [#:async async?])  void

  str : string?
  async? : boolean? = #f

method

(send a-nvim err-writeln str    
  [#:async async?])  void
  str : string?
  async? : boolean? = #f

method

(send a-nvim list-bufs [#:async async?])

  (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

(send a-nvim list-wins [#:async async?])

  (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 subscribe event    
  [#:async async?])  void
  event : string?
  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-mode [#: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

method

(send a-nvim ui-detach [#:async async?])  void

  async? : boolean? = #f

method

(send a-nvim ui-try-resize width    
  height    
  [#:async async?])  void
  width : integer?
  height : integer?
  async? : boolean? = #f

method

(send a-nvim ui-set-option name    
  value    
  [#:async async?])  void
  name : string?
  value : packable?
  async? : boolean? = #f

class

buffer% : class?

  superclass: object%

  extends: printable<%>
Represents an instance of a Neovim buffer.

method

(send a-buffer line-count [#:async async?])  integer?

  async? : boolean? = #f

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 get-var name [#:async async?])  packable?

  name : 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 del-var name [#:async async?])  void

  name : string?
  async? : boolean? = #f

method

(send a-buffer get-chagedtick [#:async async?])  integer?

  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-name [#:async async?])  string?

  async? : boolean? = #f

method

(send a-buffer set-name name    
  [#:async async?])  void
  name : string?
  async? : boolean? = #f

method

(send a-buffer is-valid? [#:async async?])  boolean?

  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

method

(send a-buffer add-highlight src-id    
  hl-group    
  line    
  col-start    
  col-end    
  [#:async async?])  integer?
  src-id : integer?
  hl-group : string?
  line : integer?
  col-start : integer?
  col-end : integer?
  async? : boolean? = #f

method

(send a-buffer clear-highlight src-id    
  line-start    
  line-end    
  [#:async async?])  void
  src-id : integer?
  line-start : integer?
  line-end : integer?
  async? : boolean? = #f

class

window% : class?

  superclass: object%

  extends: printable<%>
Represents an instance of a Neovim window.

method

(send a-window get-buf [#:async async?])  (is-a?/c buffer%)

  async? : boolean? = #f

method

(send a-window get-tabpage [#:async async?])  (is-a?/c tabpage%)

  async? : boolean? = #f

method

(send a-window get-cursor [#:async async?])

  (vector/c integer? integer? #:flat #t #:immutable #t)
  async? : boolean? = #f

method

(send a-window get-height [#:async async?])  integer?

  async? : boolean? = #f

method

(send a-window set-height height    
  [#:async async?])  void
  height : integer?
  async? : boolean? = #f

method

(send a-window get-width [#:async async?])  integer?

  async? : boolean? = #f

method

(send a-window set-width width    
  [#:async async?])  void
  width : integer?
  async? : boolean? = #f

method

(send a-window get-var name [#:async async?])  packable?

  name : string?
  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 del-var name [#:async async?])  void

  name : string?
  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

method

(send a-window get-position [#:async async?])

  (vector/c integer? integer? #:flat #t #:immutable #t)
  async? : boolean? = #f

method

(send a-window get-number [#:async async?])  integer?

  async? : boolean? = #f

method

(send a-window is-valid? [#:async async?])  boolean?

  async? : boolean? = #f

class

tabpage% : class?

  superclass: object%

  extends: printable<%>
Represents an instance of a Neovim tab page.

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.

method

(send a-tabpage get-winow [#:async async?])  (is-a?/c window%)

  async? : boolean? = #f
Returns the current window in a-tabpage.

method

(send a-tabpage get-number [#:async async?])  integer?

  async? : boolean? = #f
Returns the tab page nuber of a-tabpage.

method

(send a-tabpage get-var name    
  [#:async async?])  any/c
  name : string?
  async? : boolean? = #f
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.

method

(send a-tabpage del-var name    
  [#:async async?])  any/c
  name : string?
  async? : boolean? = #f
Deletes the value of the tab-local variable name in a-tabpage.

method

(send a-tabpage is-valid? [#:async async?])  boolean?

  async? : boolean? = #f
Checks whether a-tabpage is valid.