create
function create(
name,
callback,
attributes?,
options?): CommandDefinition;
Create a ex command with a callback function.
The builtin command js cannot be override.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Command name that is going to create. Only letters ( |
| Async callback function that implements the command. It accepts an | |
| (Optional) Attributes that control the command behavior, by default is | |
| (Optional) Options that control how the command is created, by default is |
Returns
It returns undefined is the command is newly created. Or it returns a command definition that was defined previously.
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);