import * as denopsStd from "https://deno.land/x/denops_std@v6.5.1/bufname/mod.ts";
A module to provide functions to handle Vim's buffer name.
The format of the buffer name assumed in this module is like
{scheme}://{expr}[;{params}][#{fragment}]
Where
{scheme}
is used to distinguish a buffer kind. It contains only alphabet characters.{expr}
is used to identify a buffer itself. Unusable characters, semicolons (;), and sharps (#) are replaced with percent-encoded characters.{params}
(Optional) is used to add meta information to the buffer name like query parameters of URL. Unusable characters and sharps (#) are replaced with percent-encoded characters.{fragment}
(Optional) is used to add a suffix to the buffer name for file type detection or so on. Unusable characters are replaced with percent-encoded characters.- Unusable characters are
"
,<
,>
,|
,?
, or*
. It is caused by the limitations of Vim on Windows.
For example,
denops:///Users/John Titor/test.git
βββ¬βββ βββββββββββββ¬βββββββββββββ
scheme expr
denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2
βββ¬βββ βββββββββββββ¬βββββββββββββ βββββββββββββ¬ββββββββββββ
scheme expr params
denops:///Users/John Titor/test.git#README.md
βββ¬βββ βββββββββββββ¬βββββββββββββ βββββ¬ββββ
scheme expr fragment
denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md
βββ¬βββ βββββββββββββ¬βββββββββββββ βββββββββββββ¬ββββββββββββ βββββ¬ββββ
scheme expr params fragment
Developers can use format
and parse
functions like below:
import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
import { format, parse } from "https://deno.land/x/denops_std@v6.5.1/bufname/mod.ts";
// Format
assertEquals(
format({
scheme: "denops",
expr: "/Users/John Titor/test.git",
}),
"denops:///Users/John Titor/test.git",
);
// Parse
assertEquals(
parse("denops:///Users/John Titor/test.git"),
{
scheme: "denops",
expr: "/Users/John Titor/test.git",
},
);
// Format (complex)
assertEquals(
format({
scheme: "denops",
expr: "/Users/John Titor/test.git",
params: {
foo: "foo",
bar: ["bar1", "bar2"],
},
fragment: "README.md",
}),
"denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md",
);
// Parse (complex)
assertEquals(
parse(
"denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md",
),
{
scheme: "denops",
expr: "/Users/John Titor/test.git",
params: {
foo: "foo",
bar: ["bar1", "bar2"],
},
fragment: "README.md",
},
);
Functions
Format a | |
Parse Vim's buffer name and return a |
Interfaces
Represent Vim's buffer name |