Home Explore Blog CI



neovim

9th chunk of `runtime/doc/lua.txt`
bea426d66b6414d9f73c51747fd913ebf51d300813130e360000000100000fce
 state (buffers, windows, etc) be directly
accessed from threads.

A subset of the `vim.*` stdlib is available in threads, including:

- `vim.uv` with a separate event loop per thread.
- `vim.mpack` and `vim.json` (useful for serializing messages between threads)
- `require` in threads can use Lua packages from the global |package.path|
- `print()` and `vim.inspect`
- `vim.diff`
- Most utility functions in `vim.*` that work with pure Lua values, like
  `vim.split`, `vim.tbl_*`, `vim.list_*`, etc.
- `vim.is_thread()` returns true from a non-main thread.


==============================================================================
VIM.HL                                                                *vim.hl*

vim.hl.on_yank({opts})                                      *vim.hl.on_yank()*
    Highlight the yanked text during a |TextYankPost| event.

    Add the following to your `init.vim`: >vim
        autocmd TextYankPost * silent! lua vim.hl.on_yank {higroup='Visual', timeout=300}
<

    Parameters: ~
      • {opts}  (`table?`) Optional parameters
                • higroup highlight group for yanked region (default
                  "IncSearch")
                • timeout time in ms before highlight is cleared (default 150)
                • on_macro highlight when executing macro (default false)
                • on_visual highlight when yanking visual selection (default
                  true)
                • event event structure (default vim.v.event)
                • priority integer priority (default
                  |vim.hl.priorities|`.user`)

vim.hl.priorities                                          *vim.hl.priorities*
    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 `on_yank` autocommands

                                                              *vim.hl.range()*
vim.hl.range({bufnr}, {ns}, {higroup}, {start}, {finish}, {opts})
    Apply highlight group to range of text.

    Parameters: ~
      • {bufnr}    (`integer`) Buffer number to apply highlighting to
      • {ns}       (`integer`) Namespace to add highlight to
      • {higroup}  (`string`) Highlight group to use for highlighting
      • {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()|
      • {opts}     (`table?`) A table with the following fields:
                   • {regtype}? (`string`, default: `'v'` i.e. charwise) Type
                     of range. See |getregtype()|
                   • {inclusive}? (`boolean`, default: `false`) Indicates
                     whether the range is end-inclusive
                   • {priority}? (`integer`, default:
                     `vim.hl.priorities.user`) Highlight priority
                   • {timeout}? (`integer`, default: -1 no timeout) Time in ms
                     before highlight is cleared

    Return (multiple): ~
        (`uv.uv_timer_t?`) range_timer A timer which manages how much time the
        highlight has left
        (`fun()?`) range_clear A function which allows clearing the highlight
        manually. nil is returned if timeout is not specified


==============================================================================
VIM.DIFF                                                            *vim.diff*

vim.diff({a}, {b}, {opts})                                        *vim.diff()*
    Run diff on strings {a} and {b}. Any indices returned by this function,
    either directly or via callback arguments,

Title: vim.hl: Highlighting Functions and Priorities, and vim.diff
Summary
This section details the `vim.hl` module, including `vim.hl.on_yank()` for highlighting yanked text, its parameters, and example usage in `init.vim`. It also explains `vim.hl.priorities`, a table defining default priorities for different types of highlighting. Additionally, it describes `vim.hl.range()` for applying highlight groups to a range of text within a buffer, including its parameters and return values (a timer and a clear function). Finally, it introduces `vim.diff()` function to run diff on strings.