zudo-codemirror

Type to search...

to open search from anywhere

Ex Commands

CreatedMar 29, 2026UpdatedMar 29, 2026Takeshi Takatsudo

Ex command-line mode reference and custom command definition in @replit/codemirror-vim.

Ex Commands

Ex commands are entered from normal mode by pressing :. A command-line prompt appears at the bottom of the editor where you type the command and press Enter to execute.

Built-in Ex Commands

File and Buffer Commands

CommandDescription
:wwrite (save). Requires a custom handler to do anything useful — see below.
:qquit. Requires a custom handler.
:wqwrite and quit
:e {file}edit a file (limited in browser context)

📝 Note

:w and :q have no built-in behavior in a browser editor. You must define custom handlers with Vim.defineEx() to connect them to your application’s save and close logic.

Key Mapping Commands

CommandDescription
:map {lhs} {rhs}create a key mapping (all modes)
:nmap {lhs} {rhs}normal mode mapping
:imap {lhs} {rhs}insert mode mapping
:vmap {lhs} {rhs}visual mode mapping
:noremap {lhs} {rhs}non-recursive mapping (all modes)
:nnoremap {lhs} {rhs}non-recursive normal mode mapping
:inoremap {lhs} {rhs}non-recursive insert mode mapping
:vnoremap {lhs} {rhs}non-recursive visual mode mapping
:unmap {lhs}remove a mapping (all modes)
:nunmap {lhs}remove normal mode mapping
:iunmap {lhs}remove insert mode mapping
:vunmap {lhs}remove visual mode mapping

Set Commands

CommandDescription
:set numbershow line numbers
:set nonumberhide line numbers
:set wrapenable line wrapping (requires custom option — see Vim Options)
:set nowrapdisable line wrapping

Text Manipulation Commands

CommandDescription
:sortsort lines in selection or entire buffer
:s/pattern/replacement/flagssubstitute on current line
:%s/pattern/replacement/flagssubstitute in entire buffer
:g/pattern/commandexecute command on lines matching pattern

Substitute Flags

FlagDescription
greplace all occurrences on each line (not just the first)
icase-insensitive matching
cconfirm each replacement

Substitute Examples

:s/foo/bar/          substitute first 'foo' with 'bar' on current line
:s/foo/bar/g         substitute all 'foo' with 'bar' on current line
:%s/foo/bar/g        substitute all 'foo' with 'bar' in entire buffer
:%s/foo/bar/gi       case-insensitive substitute in entire buffer
:5,10s/foo/bar/g     substitute in lines 5 through 10

Global Command Examples

:g/TODO/d            delete all lines containing 'TODO'
:g/^$/d              delete all blank lines
:g/pattern/normal dd delete lines matching pattern using normal mode command

Information Commands

CommandDescription
:markslist current marks
:registerslist register contents

Defining Custom Ex Commands

Use Vim.defineEx() to register handlers for Ex commands. This is how you make :w, :q, and other commands functional in your application.

import { Vim } from "@replit/codemirror-vim";

Vim.defineEx() Signature

Vim.defineEx(name: string, prefix: string, handler: (cm: any, params: any) => void): void
  • name — the full command name (e.g., "write")
  • prefix — the short alias (e.g., "w")
  • handler — the function to execute. Receives the CodeMirror adapter instance and a params object.

Implementing
(Write/Save)

Vim.defineEx("write", "w", function (cm, params) {
  // Your save logic here
  const content = cm.getValue();
  saveToServer(content);
});

Implementing
(Quit)

Vim.defineEx("quit", "q", function (cm, params) {
  // Your close/quit logic here
  closeEditor();
});

Implementing
(Write and Quit)

Vim.defineEx("wquit", "wq", function (cm, params) {
  const content = cm.getValue();
  saveToServer(content).then(() => {
    closeEditor();
  });
});

Custom Commands with Arguments

The params object provides access to command-line arguments.

Vim.defineEx("theme", "theme", function (cm, params) {
  const themeName = params.args?.[0];
  if (themeName) {
    applyTheme(themeName);
  }
});

This allows :theme dark or :theme light from the vim command line.

Custom Commands with Range

Ex commands that operate on a line range receive range information in params.

Vim.defineEx("upper", "upper", function (cm, params) {
  const { line: start } = params.line ?? { line: 0 };
  const { line: end } = params.lineEnd ?? { line: cm.lineCount() - 1 };
  // Operate on lines start through end
});

Revision History