Skip to main content
Version: Next

RsvimCmd

The Rsvim.cmd global object for Ex commands.

Example

// Create a alias to 'Rsvim.cmd'.
const cmd = Rsvim.cmd;

Type Aliases

Type AliasDescription

CommandAttributes

Command attributes.

See

RsvimCmd.create

CommandCallback

Command callback function, this is the backend logic that implements a user ex command.

It accepts a ctx parameter that indicates runtime information when the command is executed.

See

CommandContext

Command runtime context.

When a command is been execute, runtime information will be passed to the command callback function.

CommandDefinition

Command definition.

CommandOptions

Command options when creating a command.

See

RsvimCmd.create

Functions

FunctionDescription

create

Create a ex command with a callback function.

warning

The builtin command js cannot be override.

Throws

Throws TypeError if any parameters are invalid. Or throws Error if command name or alias already exists, but force option is not set to override existing command forcibly.

Example

async function write(ctx: RsvimCmd.CommandContext): void {
try {
const bytes = Rsvim.buf.writeSync(ctx.currentBufferId);

// Call other async APIs
const file = await Rsvim.fs.open("message.txt");
const buffer = new Uint8Array(100);
const read = await file.read(buffer);
const message = new TextDecoder().decode(buffer);

Rsvim.cmd.echo(`Buffer ${bufId} has been saved, ${bytes} bytes written with message: ${message}`);
} catch (e) {
Rsvim.cmd.echo(`Error: failed to save buffer ${bufId}, exception: ${e}`);
}
}
Rsvim.cmd.create("write", write);

echo

Echo message to the command-line.

Throws

Throws TypeError if the parameter is null or undefined or no parameter provided.

Example

Rsvim.cmd.echo("Hello Rsvim!");

get

Get ex command definition by name.

warning

The builtin js command cannot be get.

Example

const def = Rsvim.cmd.get("write");
Rsvim.cmd.echo(`Command: ${def.name}`);

list

List all registered ex command names.

warning

The builtin js command will not be listed here.

Example

Rsvim.cmd.list().forEach((name) => {
Rsvim.cmd.echo(`Command: ${name}`);
});

remove

Remove an ex command by name.

warning

The builtin command js cannot be removed.

Throws

Throws TypeError if name is not a string.

Example

Rsvim.cmd.list().forEach((cmd) => {
// Remove all registered commands.
Rsvim.cmd.remove(cmd.name);
});