Buffer Class

class pynvim.api.Buffer(session: Nvim, code_data: Tuple[int, Any])[source]

A remote Nvim buffer.

add_highlight(hl_group: str, line: int, col_start: int = 0, col_end: int = -1, src_id: int = -1, async_: Optional[bool, None] = None, **kwargs) → int[source]

Add a highlight to the buffer.

append(lines: Union[str, bytes, List[Union[str, bytes]]], index: int = -1) → None[source]

Append a string or list of lines to the buffer.

clear_highlight(src_id: int, line_start: int = 0, line_end: int = -1, async_: Optional[bool, None] = None, **kwargs) → None[source]

Clear highlights from the buffer.


Return True if the buffer is valid and loaded.

mark(name: str) → Tuple[int, int][source]

Return (row, col) tuple for a named mark.


Get the buffer name.


Get the buffer number.

range(start: int, end: int) → pynvim.api.buffer.Range[source]

Return a Range object, which represents part of the Buffer.

update_highlights(src_id: int, hls: List[Union[Tuple[str, int], Tuple[str, int, int, int]]], clear_start: Optional[int, None] = None, clear_end: int = -1, clear: bool = False, async_: bool = True) → None[source]

Add or update highlights in batch to avoid unnecessary redraws.

A src_id must have been allocated prior to use of this function. Use for instance nvim.new_highlight_source() to get a src_id for your plugin.

hls should be a list of highlight items. Each item should be a list or tuple on the form (“GroupName”, linenr, col_start, col_end) or (“GroupName”, linenr) to highlight an entire line.

By default existing highlights are preserved. Specify a line range with clear_start and clear_end to replace highlights in this range. As a shorthand, use clear=True to clear the entire buffer before adding the new highlights.


Return True if the buffer still exists.