Home Explore Blog CI



neovim

37th chunk of `runtime/doc/api.txt`
33e731150910e1a6e5c1ce4788e70c75d4f796ed8204c9520000000100000fca
  local m2  = api.nvim_buf_set_extmark(0, ns, 2, 0, {})
        -- Get extmarks only from line 3.
        local ms  = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {})
        -- Get all marks in this buffer + namespace.
        local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {})
        vim.print(ms)
<

    Attributes: ~
        Since: 0.5.0

    Parameters: ~
      • {buffer}  Buffer id, or 0 for current buffer
      • {ns_id}   Namespace id from |nvim_create_namespace()| or -1 for all
                  namespaces
      • {start}   Start of range: a 0-indexed (row, col) or valid extmark id
                  (whose position defines the bound). |api-indexing|
      • {end}     End of range (inclusive): a 0-indexed (row, col) or valid
                  extmark id (whose position defines the bound).
                  |api-indexing|
      • {opts}    Optional parameters. Keys:
                  • limit: Maximum number of marks to return
                  • details: Whether to include the details dict
                  • hl_name: Whether to include highlight group name instead
                    of id, true if omitted
                  • overlap: Also include marks which overlap the range, even
                    if their start position is less than `start`
                  • type: Filter marks by type: "highlight", "sign",
                    "virt_text" and "virt_lines"

    Return: ~
        List of `[extmark_id, row, col]` tuples in "traversal order".

                                                      *nvim_buf_set_extmark()*
nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {opts})
    Creates or updates an |extmark|.

    By default a new extmark is created when no id is passed in, but it is
    also possible to create a new mark by passing in a previously unused id or
    move an existing mark by passing in its id. The caller must then keep
    track of existing and unused ids itself. (Useful over RPC, to avoid
    waiting for the return value.)

    Using the optional arguments, it is possible to use this to highlight a
    range of text, and also to associate virtual text to the mark.

    If present, the position defined by `end_col` and `end_row` should be
    after the start position in order for the extmark to cover a range. An
    earlier end position is not an error, but then it behaves like an empty
    range (no highlighting).

    Attributes: ~
        Since: 0.5.0

    Parameters: ~
      • {buffer}  Buffer id, or 0 for current buffer
      • {ns_id}   Namespace id from |nvim_create_namespace()|
      • {line}    Line where to place the mark, 0-based. |api-indexing|
      • {col}     Column where to place the mark, 0-based. |api-indexing|
      • {opts}    Optional parameters.
                  • id : id of the extmark to edit.
                  • end_row : ending line of the mark, 0-based inclusive.
                  • end_col : ending col of the mark, 0-based exclusive.
                  • hl_group : highlight group used for the text range. This
                    and below highlight groups can be supplied either as a
                    string or as an integer, the latter of which can be
                    obtained using |nvim_get_hl_id_by_name()|.
                    Multiple highlight groups can be stacked by passing an
                    array (highest priority last).
                  • hl_eol : when true, for a multiline highlight covering the
                    EOL of a line, continue the highlight for the rest of the
                    screen line (just like for diff and cursorline highlight).
                  • virt_text : virtual text to link to this mark. A list of
                    `[text, highlight]` tuples, each representing a text chunk
                    with specified highlight. `highlight` element can either
                    be a single highlight group, or an array of multiple
                    highlight groups that will be stacked (highest priority
            

Title: nvim_buf_get_extmarks options and nvim_buf_set_extmark Function
Summary
This section details the optional parameters for `nvim_buf_get_extmarks`, including `limit`, `details`, `hl_name`, `overlap`, and `type` to filter extmarks. It also describes the `nvim_buf_set_extmark` function, which creates or updates an extmark, allowing for text highlighting and virtual text association. It explains how to define a range of text with `end_row` and `end_col` parameters and use highlight groups.