Skip to main content
Module

x/denops_std/function/nvim/mod.ts>nvim_buf_attach

📚 Standard module for denops.vim
Go to Latest
function nvim_buf_attach
import { nvim_buf_attach } from "https://deno.land/x/denops_std@v6.4.0/function/nvim/mod.ts";

Activates buffer-update events on a channel, or as Lua callbacks.

Example (Lua): capture buffer updates in a global events variable (use "print(vim.inspect(events))" to see its contents): >lua events = {} vim.api.nvim_buf_attach(0, false, { on_lines=function(...) table.insert(events, {...}) end}) <

Parameters:

  • {buffer} Buffer handle, or 0 for current buffer

  • {send_buffer} True if the initial notification should contain the whole buffer: first notification will be nvim_buf_lines_event. Else the first notification will be nvim_buf_changedtick_event. Not for Lua callbacks.

  • {opts} Optional parameters. - on_lines: Lua callback invoked on change. Return true to detach. Args: - the string "lines" - buffer handle - b:changedtick - first line that changed (zero-indexed) - last line that was changed - last line in the updated range - byte count of previous contents - deleted_codepoints (if utf_sizes is true) - deleted_codeunits (if utf_sizes is true)

               - on_bytes: lua callback invoked on change. This
                 callback receives more granular information about the
                 change compared to on_lines. Return `true` to detach. Args:
                 - the string "bytes"
                 - buffer handle
                 - b:changedtick
                 - start row of the changed text (zero-indexed)
                 - start column of the changed text
                 - byte offset of the changed text (from the start of
                   the buffer)
                 - old end row of the changed text
                 - old end column of the changed text
                 - old end byte length of the changed text
                 - new end row of the changed text
                 - new end column of the changed text
                 - new end byte length of the changed text
    
               - on_changedtick: Lua callback invoked on changedtick
                 increment without text change. Args:
                 - the string "changedtick"
                 - buffer handle
                 - b:changedtick
    
               - on_detach: Lua callback invoked on detach. Args:
                 - the string "detach"
                 - buffer handle
    
               - on_reload: Lua callback invoked on reload. The entire
                 buffer content should be considered changed. Args:
                 - the string "reload"
                 - buffer handle
    
               - utf_sizes: include UTF-32 and UTF-16 size of the
                 replaced region, as args to `on_lines`.
               - preview: also attach to command preview (i.e.
                 'inccommand') events.
    

Return: False if attach failed (invalid parameter, or buffer isn't loaded); otherwise True. TODO: LUA_API_NO_EVAL

See also:

  • nvim_buf_detach()
  • api-buffer-updates-lua

Parameters

denops: Denops
buffer: unknown
send_buffer: unknown
opts: unknown

Returns

Promise<unknown>