Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/denops_std/function/buffer.ts

๐Ÿ“š Standard module for denops.vim
Go to Latest
import * as denopsStd from "https://deno.land/x/denops_std@v4.1.5/function/buffer.ts";

Functions

Add a buffer to the buffer list with name {name} (must be a String). If a buffer for file {name} already exists, return that buffer number. Otherwise return the buffer number of the newly created buffer. When {name} is an empty string then a new buffer is always created. The buffer will not have 'buflisted' set and not be loaded yet. To add some text to the buffer use this: let bufnr = bufadd('someName') call bufload(bufnr) call setbufline(bufnr, 1, ['some', 'text']) Returns 0 on error. Can also be used as a |method|: let bufnr = 'somename'->bufadd()

The result is a Number, which is |TRUE| if a buffer called {buf} exists. If the {buf} argument is a number, buffer numbers are used.

The result is a Number, which is |TRUE| if a buffer called {buf} exists and is listed (has the 'buflisted' option set). The {buf} argument is used like with |bufexists()|.

Ensure the buffer {buf} is loaded. When the buffer name refers to an existing file then the file is read. Otherwise the buffer will be empty. If the buffer was already loaded then there is no change. If the buffer is not related to a file the no file is read (e.g., when 'buftype' is "nofile"). If there is an existing swap file for the file of the buffer, there will be no dialog, the buffer will be loaded anyway. The {buf} argument is used like with |bufexists()|.

The result is a Number, which is |TRUE| if a buffer called {buf} exists and is loaded (shown in a window or hidden). The {buf} argument is used like with |bufexists()|.

The result is the name of a buffer. Mostly as it is displayed by the :ls command, but not using special names such as "[No Name]". If {buf} is omitted the current buffer is used. If {buf} is a Number, that buffer number's name is given. Number zero is the alternate buffer for the current window. If {buf} is a String, it is used as a |file-pattern| to match with the buffer names. This is always done like 'magic' is set and 'cpoptions' is empty. When there is more than one match an empty string is returned. "" or "%" can be used for the current buffer, "#" for the alternate buffer. A full match is preferred, otherwise a match at the start, end or middle of the buffer name is accepted. If you only want a full match then put "^" at the start and "$" at the end of the pattern. Listed buffers are found first. If there is a single match with a listed buffer, that one is returned. Next unlisted buffers are searched for. If the {buf} is a String, but you want to use it as a buffer number, force it to be a Number by adding zero to it: :echo bufname("3" + 0) Can also be used as a |method|: echo bufnr->bufname()

The result is the number of a buffer, as it is displayed by the :ls command. For the use of {buf}, see |bufname()| above. If the buffer doesn't exist, -1 is returned. Or, if the {create} argument is present and TRUE, a new, unlisted, buffer is created and its number is returned. Example: let newbuf = bufnr('Scratch001', 1) Using an empty name uses the current buffer. To create a new buffer with an empty name use |bufadd()|. bufnr("$") is the last buffer: :let last_buffer = bufnr("$") The result is a Number, which is the highest buffer number of existing buffers. Note that not all buffers with a smaller number necessarily exist, because ":bwipeout" may have removed them. Use bufexists() to test for the existence of a buffer.

The result is a Number, which is the |window-ID| of the first window associated with buffer {buf}. For the use of {buf}, see |bufname()| above. If buffer {buf} doesn't exist or there is no such window, -1 is returned. Example:

Like |bufwinid()| but return the window number instead of the |window-ID|. If buffer {buf} doesn't exist or there is no such window, -1 is returned. Example:

Return a |List| with the lines starting from {lnum} to {end} (inclusive) in the buffer {buf}. If {end} is omitted, a |List| with only the line {lnum} is returned.

Set line {lnum} to {text} in buffer {buf}. This works like |setline()| for the specified buffer.