nvim_runtime_lua

vim.hl

Methods3

function M.range(buf: integer, ns: integer, hlgroup: integer | integer[] | string | string[], start: (integer, integer) | string, finish: (integer, integer) | string, opts: vim.hl.range.Opts | nil) -> (range_timer uv.uv_timer_t | nil, range_clear fun() -> nil | nil)

Apply highlight group to range of text.

Parameters
bufinteger

Buffer number to apply highlighting to

nsinteger

Namespace to add highlight to

hlgroupinteger | integer[] | string | string[]

Highlight group used for the text range. See the hl_group option in |nvimbufset_extmark()|.

start(integer, integer) | string

Start of region as a (line, column) tuple or string accepted by |getpos()|

finish(integer, integer) | string

End of region as a (line, column) tuple or string accepted by |getpos()|

optsvim.hl.range.Opts | nil
Returns
range_timeruv.uv_timer_t | nil

A timer which manages how much time the highlight has left

range_clearfun() -> nil | nil

A function which allows clearing the highlight manually. nil is returned if timeout is not specified

function M.hl_op(opts: nil | table) -> nil

Highlights the affected text region during a |TextYankPost| or |TextPutPost| event.

Add this to your init.vim:

autocmd TextYankPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300}
autocmd TextPutPost  * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300}
Parameters
optsnil | table

Optional parameters

  • event (default: vim.v.event) Event structure.
  • higroup (default: "IncSearch") Highlight group for the text region.
  • on_macro (default: false) Highlight during |macro| execution.
  • on_visual (default: true) Highlight during |Visual| mode.
  • priority (default: |vim.hl.priorities|.user) Integer priority.
  • timeout (default: 150) Time in ms before highlight is cleared.
Returns
nil
function M.on_yank(opts) -> nil
Deprecated
Use |vim.hl.hl_op()| instead.

Fields1

M.priorities: table

Table with default priorities used for highlighting:

  • syntax: 50, used for standard syntax highlighting
  • treesitter: 100, used for treesitter-based highlighting
  • semantic_tokens: 125, used for LSP semantic token highlighting
  • diagnostics: 150, used for code analysis such as diagnostics
  • user: 200, used for user-triggered highlights such as LSP document
  • symbols or hl_op autocommands