Skip to content

Overlays and Virtual Text API

Overlay Operations

addOverlay

Add a colored highlight overlay to text without modifying content Overlays are visual decorations that persist until explicitly removed. Add an overlay (visual decoration) to a buffer Use namespaces for easy batch removal (e.g., "spell", "todo"). Multiple overlays can apply to the same range; colors blend.

typescript
addOverlay(buffer_id: number, namespace: string, start: number, end: number, r: number, g: number, b: number, bg_r: number, bg_g: number, bg_b: number, underline: boolean, bold: boolean, italic: boolean, extend_to_line_end: boolean): boolean

Parameters:

NameTypeDescription
buffer_idnumberTarget buffer ID
namespacestringOptional namespace for grouping (use clearNamespace for batch removal)
startnumberStart byte offset
endnumberEnd byte offset
rnumberRed (0-255)
gnumberGreen (0-255)
bnumberuffer_id - Target buffer ID
bg_rnumber-
bg_gnumber-
bg_bnumber-
underlinebooleanAdd underline decoration
boldbooleanUse bold text
italicbooleanUse italic text
extend_to_line_endbooleanExtend background to end of visual line

removeOverlay

Remove a specific overlay by its handle

typescript
removeOverlay(buffer_id: number, handle: string): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID
handlestringThe overlay handle to remove

clearOverlaysInRange

Clear all overlays that overlap with a byte range

typescript
clearOverlaysInRange(buffer_id: number, start: number, end: number): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID
startnumberStart byte position (inclusive)
endnumberEnd byte position (exclusive)

clearAllOverlays

Remove all overlays from a buffer

typescript
clearAllOverlays(buffer_id: number): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID

addVirtualText

Add virtual text (inline decoration) at a position

typescript
addVirtualText(buffer_id: number, virtual_text_id: string, position: number, text: string, r: number, g: number, b: number, before: boolean, use_bg: boolean): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID
virtual_text_idstringUnique identifier for this virtual text
positionnumberByte position to insert at
textstringThe virtual text to display
rnumberRed color component (0-255)
gnumberGreen color component (0-255)
bnumberuffer_id - The buffer ID
beforebooleanWhether to insert before (true) or after (false) the position
use_bgbooleanWhether to use the color as background (true) or foreground (false)

removeVirtualText

Remove virtual text by ID

typescript
removeVirtualText(buffer_id: number, virtual_text_id: string): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID
virtual_text_idstringThe virtual text ID to remove

removeVirtualTextsByPrefix

Remove all virtual texts with IDs starting with a prefix

typescript
removeVirtualTextsByPrefix(buffer_id: number, prefix: string): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID
prefixstringThe prefix to match virtual text IDs against

clearVirtualTexts

Remove all virtual texts from a buffer

typescript
clearVirtualTexts(buffer_id: number): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID

clearVirtualTextNamespace

Clear all virtual texts in a namespace

typescript
clearVirtualTextNamespace(buffer_id: number, namespace: string): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID
namespacestringThe namespace to clear (e.g., "git-blame")

refreshLines

Force a refresh of line display for a buffer

typescript
refreshLines(buffer_id: number): boolean

Parameters:

NameTypeDescription
buffer_idnumberThe buffer ID

Released under the Apache 2.0 License