Home Explore Blog CI



neovim

16th chunk of `runtime/doc/api.txt`
ccc09689aa3555cd6e5feb27dc2cb8708bdd1329a82e55890000000100000fcc
 create an empty buffer using |nvim_create_buf()|,
    then display it using |nvim_open_win()|, and then call this function. Then
    |nvim_chan_send()| can be called immediately to process sequences in a
    virtual terminal having the intended size.

    Example: this `TermHl` command can be used to display and highlight raw
    ANSI termcodes, so you can use Nvim as a "scrollback pager" (for terminals
    like kitty):                     *ansi-colorize* *terminal-scrollback-pager* >lua
        vim.api.nvim_create_user_command('TermHl', function()
          vim.api.nvim_open_term(0, {})
        end, { desc = 'Highlights ANSI termcodes in curbuf' })
<

    Attributes: ~
        not allowed when |textlock| is active
        Since: 0.5.0

    Parameters: ~
      • {buffer}  Buffer to use. Buffer contents (if any) will be written to
                  the PTY.
      • {opts}    Optional parameters.
                  • on_input: Lua callback for input sent, i e keypresses in
                    terminal mode. Note: keypresses are sent raw as they would
                    be to the pty master end. For instance, a carriage return
                    is sent as a "\r", not as a "\n". |textlock| applies. It
                    is possible to call |nvim_chan_send()| directly in the
                    callback however. `["input", term, bufnr, data]`
                  • force_crlf: (boolean, default true) Convert "\n" to
                    "\r\n".

    Return: ~
        Channel id, or 0 on error

nvim_paste({data}, {crlf}, {phase})                             *nvim_paste()*
    Pastes at cursor (in any mode), and sets "redo" so dot (|.|) will repeat
    the input. UIs call this to implement "paste", but it's also intended for
    use by scripts to input large, dot-repeatable blocks of text (as opposed
    to |nvim_input()| which is subject to mappings/events and is thus much
    slower).

    Invokes the |vim.paste()| handler, which handles each mode appropriately.

    Errors ('nomodifiable', `vim.paste()` failure, …) are reflected in `err`
    but do not affect the return value (which is strictly decided by
    `vim.paste()`). On error or cancel, subsequent calls are ignored
    ("drained") until the next paste is initiated (phase 1 or -1).

    Useful in mappings and scripts to insert multiline text. Example: >lua
        vim.keymap.set('n', 'x', function()
          vim.api.nvim_paste([[
            line1
            line2
            line3
          ]], false, -1)
        end, { buffer = true })
<

    Attributes: ~
        not allowed when |textlock| is active
        Since: 0.4.0

    Parameters: ~
      • {data}   Multiline input. Lines break at LF ("\n"). May be binary
                 (containing NUL bytes).
      • {crlf}   Also break lines at CR and CRLF.
      • {phase}  -1: paste in a single call (i.e. without streaming). To
                 "stream" a paste, call `nvim_paste` sequentially with these
                 `phase` values:
                 • 1: starts the paste (exactly once)
                 • 2: continues the paste (zero or more times)
                 • 3: ends the paste (exactly once)

    Return: ~
        • true: Client may continue pasting.
        • false: Client should cancel the paste.

nvim_put({lines}, {type}, {after}, {follow})                      *nvim_put()*
    Puts text at cursor, in any mode. For dot-repeatable input, use
    |nvim_paste()|.

    Compare |:put| and |p| which are always linewise.

    Attributes: ~
        not allowed when |textlock| is active
        Since: 0.4.0

    Parameters: ~
      • {lines}   |readfile()|-style list of lines. |channel-lines|
      • {type}    Edit behavior: any |getregtype()| result, or:
                  • "b" |blockwise-visual| mode (may include width, e.g. "b3")
                  • "c" |charwise| mode
                  • "l" |linewise| mode
                  • "" guess by contents, see |setreg()|
      • {after}   If true insert after cursor (like |p|),

Title: Nvim API: Opening Terminals, Pasting, and Putting Text
Summary
This section describes the `nvim_open_term()` function, which opens a terminal instance in a buffer for displaying ANSI terminal sequences or acting as a scrollback pager. It also details `nvim_paste()`, used for pasting text at the cursor with dot-repeatable behavior, and `nvim_put()`, which puts text at the cursor with various editing behaviors (charwise, linewise, blockwise).