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

x/denops_std/function/mod.ts>bufnr

๐Ÿ“š Standard module for denops.vim
Go to Latest
function bufnr
import { bufnr } from "https://deno.land/x/denops_std@v5.0.2/function/mod.ts";

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.

Can also be used as a method:

echo bufref->bufnr()

Obsolete name: buffer_number().

Obsolete name for bufnr("$"): last_buffer_nr().

Parameters

denops: Denops
optional
buf: BufNameArg
optional
create: boolean

Returns

Promise<number>