Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Command mode syntax

Press : inside Mitos to run typable commands such as :write or :quit. For shell invocation and flags, see Starting Mitos.

Typable commands optionally accept arguments. :write for example accepts an optional path to write the file contents. The command line also supports a quoting syntax for arguments, flags to modify command behaviors, and expansions - a way to insert values from the editor. Most commands support these features but some have custom parsing rules (see the exceptions below).

Quoting

By default, command arguments are split on tabs and space characters. :open README.md CHANGELOG.md for example should open two files, README.md and CHANGELOG.md. Arguments that contain spaces can be surrounded in single quotes (') or backticks (`) to prevent the space from separating the argument, like :open 'a b.txt'.

Double quotes may be used the same way, but double quotes expand their inner content. :echo "%{cursor_line}" for example may print 1 because of the expansion for the cursor_line variable. :echo '%{cursor_line}' though prints %{cursor_line} literally: content within single quotes or backticks is interpreted as-is.

On Unix systems the backslash character may be used to escape certain characters depending on where it is used. Within an argument which isn’t surrounded by quotes, the backslash can be used to escape the space or tab characters: :open a\ b.txt is equivalent to :open 'a b.txt'. The backslash may also be used to escape quote characters (', `, ") or the percent token (%) when used at the beginning of an argument. :echo \%sh{foo} for example prints %sh{foo} instead of invoking a foo shell command and :echo \"quote prints "quote. The backslash character is treated literally in any other situation on Unix systems and always on Windows: :echo \n always prints \n.

Flags

Command flags are optional switches that can be used to alter the behavior of a command. For example the :sort command accepts an optional --reverse (or -r for short) flag which causes the sort command to reverse the sorting direction. Typing the - character shows completions for the current command’s flags, if any.

The -- flag specifies the end of flags. All arguments after -- are treated as positional arguments: :open -- -a.txt opens a file called -a.txt.

Use Up and Down to browse history matching the text already entered. Moving past the newest match restores that input. When the prompt is empty, Right accepts the history suggestion so you can edit it before running it. Repeated commands keep their most recent position in command history.

Expansions

Expansions are patterns that Mitos recognizes and replaces within the command line. Mitos recognizes anything starting with a percent token (%) as an expansion, for example %sh{echo hi!}. Expansions are particularly useful when used in commands like :echo or :noop for executing simple scripts. For example:

[keys.normal]
# Show the current Git branch in the status area.
F12 = ":echo %sh{git branch --show-current}"

Expansions take the form %[<kind>]<open><contents><close>. In %sh{echo hi!}, for example, the kind is sh - the shell expansion - and the contents are “echo hi!”, with { and } acting as opening and closing delimiters. The following open/close characters are recognized as expansion delimiter pairs: (/), [/], {/} and </>. Plus the single characters ', " or | may be used instead: %{cursor_line} is equivalent to %<cursor_line>, %[cursor_line] or %|cursor_line|.

To escape a percent character instead of treating it as an expansion, use two percent characters consecutively. To execute a shell command like date -u +'%Y-%m-%d', double the percent characters: :echo %sh{date -u +'%%Y-%%m-%%d'}.

When no <kind> is provided, Mitos will expand a variable. For example %{cursor_line} can be used as an argument to insert the line number. :echo %{cursor_line} for instance may print 1 to the statusline.

The following variables are supported:

NameDescription
cursor_lineThe line number of the primary cursor in the currently focused document, starting at 1.
cursor_columnThe column number of the primary cursor in the currently focused document, starting at 1. This is counted as the number of grapheme clusters from the start of the line rather than bytes or codepoints.
buffer_nameThe relative path of the currently focused document. [scratch] is expanded instead for scratch buffers.
file_path_absoluteThe absolute path of the currently focused document. For scratch buffers this will default to the current working directory.
buffer_directoryThe absolute parent directory of the current file, or the working directory for scratch buffers.
workspace_pathThe current file’s path relative to the workspace, or its absolute path when outside the workspace. Scratch buffers use the working directory.
clipboardThe current system clipboard value, equivalent to the first value of the + register.
line_endingA string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (\n) but on Windows systems this may be a carriage-return plus a line-feed (\r\n). The line ending kind of the currently focused document can be inspected with the :line-ending command.
current_working_directoryCurrent working directory
workspace_directoryNearest ancestor directory of the current working directory that contains .git, .svn, jj or .mitos
languageA string containing the language name of the currently focused document.
selectionA string containing the contents of the main selection of the currently focused document.
selection_line_startThe line number of the start of the main selection in the currently focused document, starting at 1.
selection_line_endThe line number of the end of the main selection in the currently focused document, starting at 1.

Aside from editor variables, the following expansions may be used:

  • Unicode %u{..}. The contents may contain up to six hexadecimal numbers corresponding to a Unicode codepoint value. For example :echo %u{25CF} prints ● to the statusline.
  • Shell %sh{..}. The contents are passed to the configured shell command. For example :echo %sh{echo "20 * 5" | bc} may print 100 on the statusline when using a shell with echo and the bc calculator installed. Shell expansions are evaluated recursively. %sh{echo '%{buffer_name}:%{cursor_line}'} for example executes a command like echo 'README.md:1': the variables within the %sh{..} expansion are evaluated before executing the shell command.
  • Interactive shell %sh_interactive{..}. Runs a shell command with exclusive access to the terminal, then uses its standard output as the expansion value. Use this for terminal programs such as fzf; their interface uses the terminal while standard output carries the selected value. Mitos resumes after the command finishes. A nonzero exit status aborts the enclosing editor command. Interactive expansions are available in submitted commands and key bindings, including custom commands; they are unavailable in formatter arguments.
  • Register %reg{..}. The contents should be a single character representing the register name. For example, :set-register a hello world followed by :echo %reg{a} prints hello world to the statusline.
  • Positional argument %arg{..}. Within a custom command, the contents are a zero-based argument index. For example, %arg{0} expands to the first argument passed to the custom command. Missing arguments expand to an empty string.

As mentioned above, double quotes can be used to surround arguments containing spaces but also support expansions within the quoted content unlike single quotes or backticks. For example :echo "circle: %u{25CF}" prints circle: ● to the statusline while :echo 'circle: %u{25CF}' prints circle: %u{25CF}.

For example, an outline script that launches fzf and prints a selected line number can be bound as follows:

[keys.normal.space]
x = { label = "File outline", command = ":goto %sh_interactive{mitos-ctags.py '%{file_path_absolute}' '%{cursor_line}'}" }

The editor restores terminal modes automatically; the script does not need to change Mitos’s keyboard or mouse protocols. Cancel in the external program with its usual keys. On Unix, suspending an interactive command with Ctrl-z aborts it and returns to Mitos.

Note that expansions are only evaluated once the Enter key is pressed in command mode.

Ordinary %sh{...} expansions run without blocking the editor. Press Escape or Ctrl-c to cancel an expansion that is taking too long. Submitting another command replaces a pending expansion. If its document or selection changes while it runs, its command is discarded.

Exceptions

The following commands support expansions but otherwise pass the given argument directly to the shell program without interpreting quotes:

  • :insert-output
  • :append-output
  • :pipe
  • :pipe-to
  • :run-shell-command

For example executing :sh echo "%{buffer_name}:%{cursor_column}" would pass text like echo "README.md:1" as an argument to the shell program: the expansions are evaluated but not the quotes. As mentioned above, percent characters can be used in shell commands by doubling the percent character. To insert the output of a command like date -u +'%Y-%m-%d' use :insert-output date -u +'%%Y-%%m-%%d'.

The :set-option and :toggle-option commands use regular parsing for the first argument - the config option name - and parse the rest depending on the config option’s type. :set-option interprets the second argument as a string for string config options and parses everything else as JSON.

:toggle-option’s behavior depends on the JSON type of the config option supplied as the first argument:

  • Booleans: only the config option name should be provided. For example :toggle-option format.on-save will flip the format.on-save option.
  • Strings: the rest of the command line is parsed with regular quoting rules. For example :toggle-option indent.heuristic hybrid tree-sitter simple cycles through “hybrid”, “tree-sitter” and “simple” values on each invocation of the command.
  • Numbers, arrays and objects: the rest of the command line is parsed as a stream of JSON values. For example :toggle-option rulers.columns [81] [51, 73] cycles through [81] and [51, 73].

When providing multiple values to :toggle-option there should be no duplicates. :toggle-option indent.heuristic hybrid simple tree-sitter simple for example would only toggle between “hybrid” and “tree-sitter” values.

:lsp-workspace-command works similarly to :toggle-option. The first argument (if present) is parsed according to normal rules. The rest of the line is parsed as JSON values. Unlike :toggle-option, string arguments for a command must be quoted. For example :lsp-workspace-command lsp.Command "foo" "bar".