RsvimCmd
The Rsvim.cmd global object for Ex commands.
Example
// Create a alias to 'Rsvim.cmd'.
const cmd = Rsvim.cmd;
Methods
create()
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 ( |
| The backend logic 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
function write(ctx: any): void {
try {
const bytes = Rsvim.buf.writeSync(bufId);
Rsvim.cmd.echo(`Buffer ${bufId} has been saved, ${bytes} bytes written`);
} catch (e) {
Rsvim.cmd.echo(`Error: failed to save buffer ${bufId}, exception: ${e}`);
}
}
Rsvim.cmd.create("write", write);
echo()
echo(message): void;
Echo message to the command-line.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| It accepts string and other primitive types, except |
Returns
void
Throws
Throws TypeError if the parameter is null or undefined or no parameter provided.
Example
Rsvim.cmd.echo("Hello Rsvim!");
list()
list(): string[];
List all registered ex command names.
The builtin js command will not be listed here.
Returns
string[]
Returns all registered ex command names, except the js command.
Example
Rsvim.cmd.list().forEach((name) => {
Rsvim.cmd.echo(`Command: ${name}`);
});
get()
get(name): CommandDefinition;
Get ex command definition by name.
The builtin js command cannot be get.
Parameters
| Parameter | Type |
|---|---|
|
|
Returns
Returns command definition by its name, except the js command.
Example
const def = Rsvim.cmd.get("write");
Rsvim.cmd.echo(`Command: ${def.name}`);
remove()
remove(name): CommandDefinition;
Remove an ex command by name.
The builtin command js cannot be removed.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The command name to be removed. |
Returns
Returns the removed RsvimCmd.CommandDefinition, or undefined if no command is been 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);
});