or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api-client.mdbuffer.mdconnection.mdindex.mdplugin-development.mdwindow-tabpage.md
tile.json

api-client.mddocs/

Neovim API Client

The Neovim and NeovimClient classes provide comprehensive access to all Neovim API operations including command execution, expression evaluation, buffer/window/tabpage management, UI operations, and event subscriptions.

Capabilities

NeovimClient Class

Extended Neovim class with connection management, returned by attach().

/**
 * Extended Neovim class that manages the RPC connection lifecycle.
 * Includes all Neovim class functionality plus connection management.
 */
class NeovimClient extends Neovim {
  /** Channel ID for this client connection */
  channelId: Promise<number>;

  /** Whether API metadata has been loaded */
  isApiReady: boolean;

  /** Static references to entity classes */
  static Buffer: typeof Buffer;
  static Window: typeof Window;
  static Tabpage: typeof Tabpage;

  /**
   * Attaches msgpack transport to read/write streams.
   * Called internally by attach() function.
   *
   * @param reader - Input stream
   * @param writer - Output stream
   */
  attach({ reader, writer }: { reader: NodeJS.ReadableStream; writer: NodeJS.WritableStream }): void;

  /**
   * Checks if a buffer has event listeners attached.
   *
   * @param buffer - Buffer to check
   * @returns true if buffer has active listeners
   */
  isAttached(buffer: Buffer): boolean;

  /**
   * Attaches an event listener to a buffer.
   *
   * @param buffer - Buffer to attach to
   * @param eventName - Event name (e.g., 'lines', 'changedtick')
   * @param cb - Callback function
   * @returns Detach function
   */
  attachBuffer(buffer: Buffer, eventName: string, cb: Function): Function;

  /**
   * Detaches an event listener from a buffer.
   *
   * @param buffer - Buffer to detach from
   * @param eventName - Event name
   * @param cb - Callback function
   * @returns true if listener was found and removed
   */
  detachBuffer(buffer: Buffer, eventName: string, cb: Function): boolean;

  /**
   * Closes the RPC connection.
   */
  close(): Promise<void>;

  /**
   * Async disposal support for using statement (Node.js 20+).
   */
  [Symbol.asyncDispose](): Promise<void>;
}

Usage Examples:

import { attach } from 'neovim';
import * as child_process from 'node:child_process';

const nvim_proc = child_process.spawn('nvim', ['--embed']);
const nvim = attach({ proc: nvim_proc });

// Get channel ID
const chanId = await nvim.channelId;
console.log('Connected via channel:', chanId);

// Check if API is ready
console.log('API ready:', nvim.isApiReady);

// Close connection
await nvim.close();

// Or use async disposal (Node.js 20+)
{
  await using nvim = attach({ proc: nvim_proc });
  await nvim.command('echo "Auto-disposed!"');
}

Neovim Class

Main API class providing access to all Neovim operations.

/**
 * Main API class for interacting with Neovim.
 * Extends BaseApi and EventEmitter.
 */
class Neovim {
  /** Reference to Buffer class */
  static Buffer: typeof Buffer;

  /** Reference to Window class */
  static Window: typeof Window;

  /** Reference to Tabpage class */
  static Tabpage: typeof Tabpage;

  // API Information
  /** Neovim API metadata (channel ID and API info) */
  apiInfo: Promise<[number, ApiInfo]>;

  // Buffer Management
  /** All buffer handles */
  buffers: Promise<Buffer[]>;

  /** Current buffer (getter/setter) */
  buffer: AsyncBuffer;

  // Window Management
  /** All window handles */
  windows: Promise<Window[]>;

  /** Current window (getter/setter) */
  window: AsyncWindow;

  // Tabpage Management
  /** All tabpage handles */
  tabpages: Promise<Tabpage[]>;

  /** Current tabpage (getter/setter) */
  tabpage: AsyncTabpage;

  // Channel Management
  /** All open channels */
  chans: Promise<Channel[]>;

  // Command Management
  /** Buffer-local user commands */
  commands: Promise<Record<string, any>>;

  // Runtime Configuration
  /** Paths in 'runtimepath' option */
  runtimePaths: Promise<string[]>;

  /** Set global working directory (setter only) */
  dir: string;

  // Editor State
  /** Current line (getter/setter) */
  line: string | Promise<string>;

  /** Current mode and blocking status */
  mode: Promise<{ mode: string; blocking: boolean }>;

  // Colors and UI
  /** Map of defined colors */
  colorMap: Promise<{ [name: string]: number }>;

  /** List of attached UIs */
  uis: Promise<Ui[]>;

  // Namespaces
  /** All namespaces */
  namespaces: Promise<{ [name: string]: number }>;

  // Inherited from BaseApi
  /**
   * Compare with another API object.
   *
   * @param other - Object to compare
   * @returns true if objects are equal
   */
  equals(other: any): boolean;

  /**
   * Send RPC request to Neovim.
   *
   * @param name - API method name
   * @param args - Method arguments
   * @returns Response from Neovim
   */
  request(name: string, args?: any[]): Promise<any>;

  /**
   * Send notification to Neovim (non-blocking).
   *
   * @param name - Notification name
   * @param args - Notification arguments
   */
  notify(name: string, args: any[]): void;

  /**
   * Get global variable (g:var).
   *
   * @param name - Variable name
   * @returns Variable value
   */
  getVar(name: string): Promise<VimValue>;

  /**
   * Set global variable (g:var).
   *
   * @param name - Variable name
   * @param value - Variable value
   */
  setVar(name: string, value: VimValue): Promise<void>;

  /**
   * Delete global variable (g:var).
   *
   * @param name - Variable name
   */
  deleteVar(name: string): Promise<void>;

  /**
   * Get global option.
   *
   * @param name - Option name
   * @returns Option value
   */
  getOption(name: string): Promise<VimValue>;

  /**
   * Set global option.
   *
   * @param name - Option name
   * @param value - Option value
   */
  setOption(name: string, value: VimValue): Promise<void>;
}

type VimValue = number | boolean | string | number[] | { [key: string]: any };
type AsyncBuffer = Promise<Buffer> & Omit<Buffer, 'id' | 'isAttached'>;
type AsyncWindow = Promise<Window> & Omit<Window, 'id'>;
type AsyncTabpage = Promise<Tabpage>;

interface ApiInfo {
  version: { major: number; minor: number; patch: number };
  functions: any[];
  ui_events: any[];
  types: any[];
  error_types: any[];
  [key: string]: any;
}

interface Channel {
  id: number;
  stream: string;
  mode: string;
  [key: string]: any;
}

type Ui = UiAttachOptions & {
  height: number;
  width: number;
  chan?: number;
}

interface Command {
  name: string;
  nargs: string;
  range: string;
  bang: boolean;
  bar: boolean;
  register: boolean;
  definition: string;
  script_id: number;
  complete?: string | null;
  addr?: any;
  count?: any;
  complete_arg?: any;
}

Command Execution

Execute Vim ex-commands and get output.

/**
 * Execute an ex-command.
 *
 * @param arg - Ex-command string
 * @returns Command result
 */
command(arg: string): Promise<any>;

/**
 * Execute ex-command and capture output.
 *
 * @param arg - Ex-command string
 * @returns Command output as string
 */
commandOutput(arg: string): Promise<string>;

/**
 * Get user-defined commands.
 *
 * @param options - Optional filter options
 * @returns Map of command name to command info
 */
getCommands(options?: object): Promise<Record<string, any>>;

Usage Examples:

// Execute commands
await nvim.command('vsp');
await nvim.command('set number');
await nvim.command('e ~/file.txt');

// Get command output
const output = await nvim.commandOutput('ls');
console.log('Buffers:', output);

const version = await nvim.commandOutput('version');
console.log(version);

// Get user commands
const commands = await nvim.commands;
console.log('Available commands:', Object.keys(commands));

const allCommands = await nvim.getCommands();
console.log('All commands:', allCommands);

Evaluation and Execution

Evaluate VimL expressions, execute Lua code, and call functions.

/**
 * Evaluate a VimL expression.
 *
 * @param expr - VimL expression
 * @returns Expression result
 */
eval(expr: string): Promise<VimValue>;

/**
 * Execute Lua code in Neovim.
 *
 * @param code - Lua code string
 * @param args - Arguments passed to Lua code
 * @returns Lua execution result
 */
lua(code: string, args?: VimValue[]): Promise<VimValue>;

/**
 * Execute Lua code (alias for lua()).
 *
 * @param code - Lua code string
 * @param args - Arguments passed to Lua code
 * @returns Lua execution result
 */
executeLua(code: string, args?: VimValue[]): Promise<VimValue>;

/**
 * Call a VimL function.
 *
 * @param fname - Function name
 * @param args - Function arguments
 * @returns Function result
 */
call(fname: string, args?: VimValue | VimValue[]): Promise<any>;

/**
 * Call a VimL function (alias for call()).
 *
 * @param fname - Function name
 * @param args - Function arguments
 * @returns Function result
 */
callFunction(fname: string, args?: VimValue | VimValue[]): Promise<any>;

/**
 * Call a VimL dictionary function.
 *
 * @param dict - Dictionary object
 * @param fname - Function name
 * @param args - Function arguments
 * @returns Function result
 */
callDictFunction(dict: object, fname: string, args?: VimValue | VimValue[]): Promise<object>;

/**
 * Call multiple API methods atomically.
 * Either all succeed or all fail.
 *
 * @param calls - Array of [method, args] tuples
 * @returns [results, error_occurred]
 */
callAtomic(calls: VimValue[]): Promise<[any[], boolean]>;

Usage Examples:

// Evaluate VimL expressions
const winCount = await nvim.eval('winnr("$")');
console.log('Window count:', winCount);

const bufName = await nvim.eval('bufname("%")');
console.log('Current buffer:', bufName);

// Execute Lua code
await nvim.lua('print("Hello from Lua!")');

const luaResult = await nvim.lua('return ... * 2', [21]);
console.log('Lua result:', luaResult); // 42

await nvim.lua(`
  vim.api.nvim_buf_set_lines(0, 0, 1, false, {"Line from Lua"})
`);

// Call VimL functions
const lineCount = await nvim.call('line', ['$']);
console.log('Lines:', lineCount);

const expandedPath = await nvim.call('expand', ['%:p']);
console.log('Full path:', expandedPath);

const files = await nvim.call('glob', ['*.js', false, true]);
console.log('JS files:', files);

// Call multiple operations atomically
const [results, hasError] = await nvim.callAtomic([
  ['nvim_command', ['vsp']],
  ['nvim_command', ['enew']],
  ['nvim_buf_set_lines', [0, 0, -1, false, ['Line 1', 'Line 2']]]
]);

if (!hasError) {
  console.log('All operations succeeded');
}

Buffer Operations

Create and manage buffers.

/**
 * Create a new buffer.
 *
 * @param listed - Whether buffer appears in buffer list
 * @param scratch - Whether buffer is scratch (no file, no undo)
 * @returns New buffer handle
 */
createBuffer(listed: boolean, scratch: boolean): Promise<Buffer | number>;

/**
 * Get all buffers (same as buffers getter).
 *
 * @returns Array of buffer handles
 */
getBuffers(): Promise<Buffer[]>;

Usage Examples:

// Create buffers
const scratchBuf = await nvim.createBuffer(false, true);
const normalBuf = await nvim.createBuffer(true, false);

// Get all buffers
const allBuffers = await nvim.buffers;
console.log('Buffer count:', allBuffers.length);

for (const buf of allBuffers) {
  const name = await buf.name;
  const lineCount = await buf.length;
  console.log(`Buffer ${buf.id}: ${name} (${lineCount} lines)`);
}

// Set current buffer
const firstBuf = allBuffers[0];
nvim.buffer = firstBuf;

// Get current buffer
const currentBuf = await nvim.buffer;
await currentBuf.append(['New line']);

Window Operations

Create and manage windows.

/**
 * Open a new window (floating or external).
 *
 * @param buffer - Buffer to display in window
 * @param enter - Whether to enter the window
 * @param options - Window configuration
 * @returns New window handle
 */
openWindow(buffer: Buffer, enter: boolean, options: OpenWindowOptions): Promise<Window | number>;

/**
 * Configure window layout and position.
 *
 * @param window - Window to configure
 * @param options - Configuration options
 * @returns Configuration result
 */
windowConfig(window: Window, options?: object): any;

/**
 * Close a window.
 *
 * @param window - Window to close
 * @param force - Force close even if buffer has unsaved changes
 * @returns Close result
 */
windowClose(window: Window, force: boolean): any;

/**
 * Get all windows.
 *
 * @returns Array of window handles
 */
getWindows(): Promise<Window[]>;

/**
 * Get current window.
 *
 * @returns Current window handle
 */
getWindow(): AsyncWindow;

/**
 * Set current window.
 *
 * @param win - Window to make current
 */
setWindow(win: Window): Promise<void>;

interface OpenWindowOptions {
  external?: boolean;
  focusable?: boolean;
  width?: number;
  height?: number;
  bufpos?: [number, number];
  row?: number;
  col?: number;
  anchor?: string;
  relative?: string;
  style?: string;
  border?: string | string[];
}

Usage Examples:

// Get all windows
const windows = await nvim.windows;
console.log('Window count:', windows.length);

// Set current window
const firstWin = windows[0];
await nvim.setWindow(firstWin);

// Get current window
const currentWin = await nvim.window;
const [height, width] = await Promise.all([currentWin.height, currentWin.width]);
console.log(`Window size: ${width}x${height}`);

// Open floating window
const buf = await nvim.createBuffer(false, true);
const floatWin = await nvim.openWindow(buf, true, {
  relative: 'editor',
  width: 50,
  height: 10,
  row: 5,
  col: 10,
  anchor: 'NW',
  style: 'minimal',
  border: 'rounded'
});

// Configure window
await nvim.windowConfig(floatWin, {
  relative: 'editor',
  width: 60,
  height: 15,
  row: 10,
  col: 20
});

// Close window
await nvim.windowClose(floatWin, false);

Tabpage Operations

Manage tabpages.

// All tabpage properties and methods are accessed via the Tabpage class
// See Window and Tabpage Operations documentation

Usage Examples:

// Get all tabpages
const tabpages = await nvim.tabpages;
console.log('Tabpage count:', tabpages.length);

// Get current tabpage
const currentTab = await nvim.tabpage;
const tabNum = await currentTab.number;
console.log('Current tabpage:', tabNum);

// Set current tabpage
nvim.tabpage = tabpages[0];

// Get windows in tabpage
const tabWindows = await currentTab.windows;
console.log('Windows in tabpage:', tabWindows.length);

Line Operations

Manipulate the current line.

/**
 * Get the current line.
 *
 * @returns Current line text
 */
getLine(): Promise<string>;

/**
 * Set the current line.
 *
 * @param line - New line text
 */
setLine(line: string): Promise<any>;

/**
 * Delete the current line.
 */
deleteCurrentLine(): Promise<any>;

Usage Examples:

// Get current line
const currentLine = await nvim.line;
console.log('Current line:', currentLine);

// Set current line
nvim.line = 'New line content';

// Delete current line
await nvim.deleteCurrentLine();

// Using methods
const line = await nvim.getLine();
await nvim.setLine('Modified: ' + line);

Variable Operations

Get and set Vim variables.

/**
 * Get a v: variable (Vim predefined variable).
 *
 * @param name - Variable name (without v: prefix)
 * @returns Variable value
 */
getVvar(name: string): Promise<VimValue>;

/**
 * Set a v: variable.
 *
 * @param name - Variable name (without v: prefix)
 * @param value - Variable value
 */
setVvar(name: string, value: VimValue): Promise<void>;

Usage Examples:

// Get v: variables
const count = await nvim.getVvar('count');
const register = await nvim.getVvar('register');
const errMsg = await nvim.getVvar('errmsg');

console.log('Count:', count);
console.log('Register:', register);
console.log('Last error:', errMsg);

// Set v: variables
await nvim.setVvar('errmsg', 'Custom error');
await nvim.setVvar('count', 42);

// Global variables (g:)
await nvim.setVar('my_global_var', 'hello');
const myVar = await nvim.getVar('my_global_var');
console.log('My var:', myVar);

await nvim.deleteVar('my_global_var');

Input Operations

Send input to Neovim.

/**
 * Send input keys to Neovim (blocking).
 * Keys are processed as if typed by user.
 *
 * @param keys - Key sequence
 * @param mode - Mode flags ('n', 'v', 'i', 'm', 't', etc.)
 * @param escapeCsi - Whether to escape CSI bytes
 */
feedKeys(keys: string, mode: string, escapeCsi: boolean): Promise<any>;

/**
 * Queue raw user input (non-blocking).
 *
 * @param keys - Input string
 * @returns Number of bytes written
 */
input(keys: string): Promise<number>;

/**
 * Send mouse event to Neovim.
 *
 * @param button - Mouse button ('left', 'right', 'middle', 'wheel')
 * @param action - Mouse action ('press', 'drag', 'release')
 * @param modifier - Modifier keys (empty string for none)
 * @param grid - Grid number
 * @param row - Row position
 * @param col - Column position
 */
inputMouse(button: string, action: string, modifier: string, grid: number, row: number, col: number): Promise<any>;

Usage Examples:

// Feed keys (blocking)
await nvim.feedKeys('i', 'n', true);  // Enter insert mode
await nvim.feedKeys('Hello', 'm', true);  // Type text
await nvim.feedKeys('\\<Esc>', 'n', true);  // Exit insert mode

// Input (non-blocking)
await nvim.input('iHello World');
await nvim.input('\\<Esc>');

// Mouse input
await nvim.inputMouse('left', 'press', '', 1, 10, 20);
await nvim.inputMouse('left', 'release', '', 1, 10, 20);

Output Operations

Write to Neovim's output and error buffers.

/**
 * Write to output buffer (does not append newline).
 *
 * @param str - String to write
 */
outWrite(str: string): Promise<any>;

/**
 * Write line to output buffer (appends newline).
 *
 * @param str - String to write
 */
outWriteLine(str: string): Promise<any>;

/**
 * Write to error buffer (does not append newline).
 *
 * @param str - Error message
 */
errWrite(str: string): Promise<any>;

/**
 * Write line to error buffer (appends newline).
 *
 * @param str - Error message
 */
errWriteLine(str: string): Promise<any>;

Usage Examples:

// Output messages
await nvim.outWrite('Processing...');
await nvim.outWriteLine(' done!');

// Error messages
await nvim.errWrite('Error: ');
await nvim.errWriteLine('Something went wrong!');

Keymap and Highlight Operations

Query keymaps and highlights.

/**
 * Get global key mappings for a mode.
 *
 * @param mode - Mode ('n', 'v', 'i', 'x', etc.)
 * @returns Array of mapping objects
 */
getKeymap(mode: string): Promise<object[]>;

/**
 * Get color value by name.
 *
 * @param name - Color name
 * @returns RGB color value
 */
getColorByName(name: string): Promise<number>;

/**
 * Get highlight definition by name or ID.
 *
 * @param nameOrId - Highlight group name or ID
 * @param isRgb - Return RGB colors instead of cterm colors
 * @returns Highlight definition
 */
getHighlight(nameOrId: string | number, isRgb?: boolean): Promise<object> | void;

/**
 * Get highlight definition by name.
 *
 * @param name - Highlight group name
 * @param isRgb - Return RGB colors
 * @returns Highlight definition
 */
getHighlightByName(name: string, isRgb?: boolean): Promise<object>;

/**
 * Get highlight definition by ID.
 *
 * @param id - Highlight ID
 * @param isRgb - Return RGB colors
 * @returns Highlight definition
 */
getHighlightById(id: number, isRgb?: boolean): Promise<object>;

Usage Examples:

// Get keymaps
const normalMaps = await nvim.getKeymap('n');
console.log('Normal mode mappings:', normalMaps);

// Get colors
const redValue = await nvim.getColorByName('Red');
console.log('Red color value:', redValue);

const colorMap = await nvim.colorMap;
console.log('All colors:', colorMap);

// Get highlights
const normalHl = await nvim.getHighlightByName('Normal', true);
console.log('Normal highlight:', normalHl);

const commentHl = await nvim.getHighlightById(1, true);
console.log('Comment highlight:', commentHl);

Process Operations

Query process information.

/**
 * Get information about a process.
 *
 * @param pid - Process ID
 * @returns Process information
 */
getProc(pid: number): Promise<Proc>;

/**
 * Get child processes of a process.
 *
 * @param pid - Parent process ID
 * @returns Array of child process info
 */
getProcChildren(pid: number): Promise<Proc[]>;

interface Proc {
  pid: number;
  ppid: number;
  name: string;
  [key: string]: any;
}

Usage Examples:

// Get process info
const nvimProc = await nvim.getProc(process.pid);
console.log('Process:', nvimProc);

// Get child processes
const children = await nvim.getProcChildren(process.pid);
console.log('Child processes:', children);

Parsing and String Operations

Parse expressions and manipulate strings.

/**
 * Parse a VimL expression into AST.
 *
 * @param expr - VimL expression
 * @param flags - Parser flags
 * @param highlight - Include highlight info
 * @returns AST representation
 */
parseExpression(expr: string, flags: string, highlight: boolean): Promise<object>;

/**
 * Replace terminal codes in string.
 *
 * @param str - String with terminal codes
 * @param fromPart - From special codes
 * @param doIt - Execute the codes
 * @param special - Special mode
 * @returns String with codes replaced
 */
replaceTermcodes(str: string, fromPart: boolean, doIt: boolean, special: boolean): Promise<string>;

/**
 * Calculate display width of string.
 *
 * @param str - String to measure
 * @returns Display width in cells
 */
strWidth(str: string): Promise<number>;

Usage Examples:

// Parse expression
const ast = await nvim.parseExpression('2 + 2', '', false);
console.log('AST:', ast);

// Replace terminal codes
const withCodes = await nvim.replaceTermcodes('<C-W>v', true, true, true);
console.log('Replaced:', withCodes);

// String width
const width = await nvim.strWidth('Hello 世界');
console.log('Display width:', width);

UI Operations

Attach and manage UI interfaces.

/**
 * Attach a UI to Neovim.
 *
 * @param width - UI width in cells
 * @param height - UI height in cells
 * @param options - UI capabilities and options
 */
uiAttach(width: number, height: number, options: UiAttachOptions): Promise<void>;

/**
 * Detach the UI.
 */
uiDetach(): Promise<void>;

/**
 * Try to resize the UI.
 *
 * @param width - New width
 * @param height - New height
 */
uiTryResize(width: number, height: number): Promise<void>;

/**
 * Try to resize a specific grid.
 *
 * @param grid - Grid number
 * @param width - New width
 * @param height - New height
 */
uiTryResizeGrid(grid: number, width: number, height: number): Promise<void>;

/**
 * Set a UI option.
 *
 * @param name - Option name
 * @param value - Option value
 */
uiSetOption(name: string, value: any): Promise<void>;

interface UiAttachOptions {
  rgb?: boolean;
  override?: boolean;
  ext_cmdline?: boolean;
  ext_hlstate?: boolean;
  ext_linegrid?: boolean;
  ext_messages?: boolean;
  ext_multigrid?: boolean;
  ext_popupmenu?: boolean;
  ext_tabline?: boolean;
  ext_termcolors?: boolean;
  ext_wildmenu?: boolean;
}

Usage Examples:

// Attach UI (for building custom Neovim UIs)
await nvim.uiAttach(80, 24, {
  rgb: true,
  ext_linegrid: true,
  ext_multigrid: true
});

// Handle UI events
nvim.on('redraw', (events) => {
  for (const [name, ...args] of events) {
    console.log('UI event:', name, args);
  }
});

// Resize UI
await nvim.uiTryResize(100, 30);

// Detach UI
await nvim.uiDetach();

// Get attached UIs
const uis = await nvim.uis;
console.log('Attached UIs:', uis);

Event Operations

Subscribe to Neovim events.

/**
 * Subscribe to event broadcasts from Neovim.
 *
 * @param event - Event name
 */
subscribe(event: string): Promise<void>;

/**
 * Unsubscribe from event broadcasts.
 *
 * @param event - Event name
 */
unsubscribe(event: string): Promise<void>;

Usage Examples:

// Subscribe to events
await nvim.subscribe('BufEnter');
await nvim.subscribe('VimLeave');

// Handle events (using EventEmitter interface)
nvim.on('notification', (method, args) => {
  console.log('Notification:', method, args);
});

// Unsubscribe
await nvim.unsubscribe('BufEnter');

Namespace Operations

Create and manage namespaces for highlights and virtual text.

/**
 * Create or get a namespace.
 *
 * @param name - Namespace name (optional, generates ID if not provided)
 * @returns Namespace ID
 */
createNamespace(name?: string): Promise<number>;

/**
 * Get all namespaces.
 *
 * @returns Map of namespace name to ID
 */
getNamespaces(): Promise<{ [name: string]: number }>;

Usage Examples:

// Create namespaces
const ns1 = await nvim.createNamespace('my-plugin');
const ns2 = await nvim.createNamespace(); // Anonymous namespace

// Get all namespaces
const namespaces = await nvim.namespaces;
console.log('Namespaces:', namespaces);

// Use namespace for highlights
const buf = await nvim.buffer;
await buf.addHighlight({
  hlGroup: 'Error',
  line: 0,
  colStart: 0,
  colEnd: 5,
  srcId: ns1
});

// Clear namespace
await buf.clearNamespace({ nsId: ns1 });

Popup Menu Operations

Control completion popup menu.

/**
 * Select an item in the completion popup menu.
 *
 * @param item - Item index (-1 to select original text)
 * @param insert - Insert selected text
 * @param finish - Finish completion
 * @param opts - Additional options
 */
selectPopupmenuItem(item: number, insert: boolean, finish: boolean, opts?: object): Promise<any>;

Usage Examples:

// Select completion item
await nvim.selectPopupmenuItem(0, true, false);

// Select and finish
await nvim.selectPopupmenuItem(1, true, true);

// Cancel completion (select original)
await nvim.selectPopupmenuItem(-1, false, true);

Client Information

Set client information.

/**
 * Identify this client to Neovim.
 *
 * @param name - Client name
 * @param version - Version object
 * @param type - Client type ('remote', 'embedder', 'host', 'plugin')
 * @param methods - Exposed RPC methods
 * @param attributes - Client attributes
 */
setClientInfo(name: string, version: object, type: string, methods: object, attributes: object): void;

Usage Examples:

// Set client info
nvim.setClientInfo(
  'my-app',
  { major: 1, minor: 0, patch: 0 },
  'remote',
  {},
  { website: 'https://example.com' }
);

// Get API info (includes client channel)
const [channelId, apiInfo] = await nvim.apiInfo;
console.log('Channel:', channelId);
console.log('API version:', apiInfo.version);

Channel Operations

Get channel information.

/**
 * Get information about a channel.
 *
 * @param chan - Channel ID
 * @returns Channel information
 */
getChanInfo(chan: number): Promise<Channel>;

Usage Examples:

// Get current channel
const channelId = await nvim.channelId;
const chanInfo = await nvim.getChanInfo(channelId);
console.log('This channel:', chanInfo);

// Get all channels
const allChans = await nvim.chans;
console.log('All channels:', allChans);

for (const chan of allChans) {
  console.log('Channel:', chan);
}

Process Control

Quit Neovim.

/**
 * Quit Neovim.
 * Sends quit command to Neovim instance.
 */
quit(): void;

Usage Examples:

// Quit Neovim
nvim.quit();

// Wait for process to exit
nvim_proc.on('exit', (code) => {
  console.log('Neovim exited with code:', code);
});

Important Notes

  • All methods return Promises and should be awaited
  • The Neovim class extends EventEmitter - you can listen to 'notification' and other events
  • Getters like buffer, window, line return Promises when accessed as getters
  • Setters like buffer = buf, window = win, line = "text" also trigger async operations
  • Use AsyncBuffer, AsyncWindow, AsyncTabpage types for properties that return promisified entities
  • Many operations have both camelCase (JavaScript) and snake_case (Neovim API) versions
  • The NeovimClient class adds connection management on top of Neovim
  • Always handle errors with try/catch as API calls can fail
  • Use callAtomic() for batch operations that should succeed or fail together