Overview
TheVim.defineEx() function allows you to create custom Ex commands (colon commands) in CodeMirror Vim mode. Ex commands are executed from command mode (entered with :).
Signature
Parameters
The full name of the Ex command. This is the complete command name that users can type.
The shortest unique prefix for the command. Users can type this shorter version instead of the full name.For example, if
name is "write" and prefix is "w", users can execute the command with either :write or :w.The function to execute when the command is invoked. Receives:
cm(CodeMirror) - The editor instanceparams(ExParams) - Command parameters including:commandName(string) - The command name as typedargString(string) - The argument stringargs(string[]) - Parsed arguments arrayinput(string) - The full command inputline(number) - Starting line numberlineEnd(number) - Ending line number
Return Value
This function does not return a value.
Examples
Basic Save Command
Define a:write (:w) command to save the file:
Command with Arguments
Define a command that accepts arguments:Line Range Command
Define a command that operates on a line range:Integration with Editor Features
Define a command that integrates with your application:Notes
- The
prefixmust be a prefix ofname, otherwise an error is thrown - Ex commands are global and available in all editor instances
- If a command with the same name or prefix already exists, it will be overridden
- Commands are executed in normal mode
- The
params.lineandparams.lineEndare automatically parsed from range syntax (e.g.,:1,5command)
ExParams Interface
See Also
- Vim.defineOperator() - Define custom operators
- Vim.defineAction() - Define custom actions
- Vim.map() - Create key mappings

