Skip to main content
Module

x/denops_std/buffer/mod.ts

📚 Standard module for denops.vim
Go to Latest
import * as denopsStd from "https://deno.land/x/denops_std@v6.1.0/buffer/mod.ts";

A module to provide Vim buffer utility functions

import type { Denops } from "https://deno.land/x/denops_std@v6.1.0/mod.ts";
import * as fn from "https://deno.land/x/denops_std@v6.1.0/function/mod.ts";
import * as buffer from "https://deno.land/x/denops_std@v6.1.0/buffer/mod.ts";

export async function main(denops: Denops): Promise<void> {
  // Open `README.md`
  // Same as `:edit README.md`
  await buffer.open(denops, "README.md");

  // Open `LICENSE` with given options
  // Same as `:keepjumps keepalt edit ++enc=sjis ++ff=dos LICENSE`
  await buffer.open(denops, "LICENSE", {
    mods: "keepjumps keepalt",
    cmdarg: "++enc=sjis ++ff=dos",
  });

  const bufnr = await fn.bufnr(denops);

  // Append the content under the cursor position of the `bufnr` buffer
  await buffer.append(denops, bufnr, ["Hello", "World"]);

  // Set the content of the `bufnr` buffer
  await buffer.replace(denops, bufnr, ["Hello", "World"]);

  // Concrete the buffer.
  // - The `buftype` option become "nofile"
  // - The `swapfile` become disabled
  // - The `modifiable` become disabled
  // - The content of the buffer is restored on `BufReadCmd` synchronously
  await buffer.concrete(denops, bufnr);

  // Decorate the specified buffer with decorations
  await buffer.decorate(denops, bufnr, [
    {
      line: 1,
      column: 1,
      length: 10,
      highlight: "Special",
    },
    {
      line: 2,
      column: 2,
      length: 3,
      highlight: "Comment",
    },
  ]);
}

Variables

v
assertFileFormat
deprecated

Assert that the value is FileFormat.

v
ensureFileFormat
deprecated

Ensure that the value is FileFormat.

Predicate that the value is FileFormat.

v
maybeFileFormat
deprecated

Maybe that the value is FileFormat.

Functions

Append content under the current cursor position or given lnum of the buffer

Concrete the buffer.

Decode raw binary content for string array for the bufnr buffer

Decorate the specified buffer with decorations

Ensure the executor is executed under the specified buffer

Ensure the executor is executed under a modifiable buffer

Open a bufname buffer with given options on the current window

Reload the content of the bufnr buffer

Replace the content of the bufnr buffer

Undecorate the specified buffer