Home Explore Blog CI



neovim

7th chunk of `runtime/doc/api.txt`
b6327fff4237c4fcd125cd5a60bf07e7b1c3b9240a9a6e410000000100000fa0
 as a group
and delete or replace all at once.

The intended use case are linter or semantic highlighter plugins that monitor
a buffer for changes, and in the background compute highlights to the buffer.
Another use case are plugins that show output in an append-only buffer, and
want to add highlights to the outputs. Highlight data cannot be preserved
on writing and loading a buffer to file, nor in undo/redo cycles.

Highlights are registered using the |nvim_buf_set_extmark()| function, which
adds highlights as |extmarks|. If highlights need to be tracked or manipulated
after adding them, the returned |extmark| id can be used. >lua
  -- create the highlight through an extmark
  extid = vim.api.nvim_buf_set_extmark(buf, ns_id, line, col_start, {end_col = col_end, hl_group = hl_group})

  -- example: modify the extmark's highlight group
  vim.api.nvim_buf_set_extmark(buf, ns_id, line, col_start, {end_col = col_end, hl_group = NEW_HL_GROUP, id = extid})

  -- example: change the highlight's position
  vim.api.nvim_buf_set_extmark(buf, ns_id, NEW_LINE, col_start, {end_col = col_end, hl_group = NEW_HL_GROUP, id = extid})
<

See also |vim.hl.range()|.

==============================================================================
Floating windows				*api-floatwin* *floating-windows*

Floating windows ("floats") are displayed on top of normal windows.  This is
useful to implement simple widgets, such as tooltips displayed next to the
cursor. Floats are fully functional windows supporting user editing, common
|api-window| calls, and most window options (except 'statusline').

Two ways to create a floating window:
- |nvim_open_win()| creates a new window (needs a buffer, see |nvim_create_buf()|)
- |nvim_win_set_config()| reconfigures a normal window into a float

To close it use |nvim_win_close()| or a command such as |:close|.

To check whether a window is floating, check whether the `relative` option in
its config is non-empty: >lua

    if vim.api.nvim_win_get_config(window_id).relative ~= '' then
      -- window with this window_id is floating
    end
<

Buffer text can be highlighted by typical mechanisms (syntax highlighting,
|api-highlights|). The |hl-NormalFloat| group highlights normal text;
'winhighlight' can be used as usual to override groups locally. Floats inherit
options from the current window; specify `style=minimal` in |nvim_open_win()|
to disable various visual features such as the 'number' column.

Other highlight groups specific to floating windows:
- |hl-FloatBorder| for window's border
- |hl-FloatTitle| for window's title
- |hl-FloatFooter| for window's footer

Currently, floating windows don't support some widgets like scrollbar.

The output of |:mksession| does not include commands for restoring floating
windows.

Example: create a float with scratch buffer: >vim

    let buf = nvim_create_buf(v:false, v:true)
    call nvim_buf_set_lines(buf, 0, -1, v:true, ["test", "text"])
    let opts = {'relative': 'cursor', 'width': 10, 'height': 2, 'col': 0,
        \ 'row': 1, 'anchor': 'NW', 'style': 'minimal'}
    let win = nvim_open_win(buf, 0, opts)
    " optional: change highlight, otherwise Pmenu is used
    call nvim_set_option_value('winhl', 'Normal:MyHighlight', {'win': win})
<

==============================================================================
Extended marks                       *api-extended-marks* *extmarks* *extmark*

Extended marks (extmarks) represent buffer annotations that track text changes
in the buffer. They can represent cursors, folds, misspelled words, anything
that needs to track a logical location in the buffer over time. |api-indexing|

Extmark position works like a "vertical bar" cursor: it exists between
characters. Thus, the maximum extmark index on a line is 1 more than the
character index: >

     f o o b a r      line contents
     0 1 2 3 4 5      character positions (0-based)
    0 1 2 3 4 5 6     extmark positions (0-based)

Extmarks have "forward gravity": if you place the

Title: Extmarks and Floating Windows in Nvim API
Summary
This section discusses the usage of extended marks (extmarks) for buffer annotations, highlighting use cases for linter and semantic highlighter plugins, and how highlights are registered using `nvim_buf_set_extmark()`. It provides examples of how to create and modify highlights using extmarks. It also covers floating windows, explaining how to create and configure them using `nvim_open_win()` and `nvim_win_set_config()`, how to check if a window is floating, and how to apply highlighting and styles to them.