Parser for Vim-style : command-line input.
Converts a raw string (without the leading :) into a structured
parsed/0 value that the editor can act on.
Supports Vim-style range prefixes (1,10 | % | . | $ | '<,'>) on all commands.
Supported commands
| Input | Result |
|---|---|
w | {:save, []} |
w! | {:force_save, []} |
q | {:quit, []} |
q! | {:force_quit, []} |
qa | {:quit_all, []} |
qa! | {:force_quit_all, []} |
wq | {:save_quit, []} |
e <filename> | {:edit, filename} |
e! | {:force_edit, []} |
cq | {:abort_quit, []} |
<number> | {:goto_line, number} |
1,10s/x/y/ | {:substitute, range, ...} |
| anything else | {:unknown, original_string} |
Summary
Types
Structured result of parsing a command-line string.
Range specification for ex commands.
Flags for :sort command (reverse, numeric, unique).
Flags for :%s substitution.
Types
@type parsed() :: {:save, []} | {:force_save, []} | {:quit, []} | {:force_quit, []} | {:quit_all, []} | {:force_quit_all, []} | {:abort_quit, []} | {:save_quit, []} | {:save_quit_all, []} | {:edit, String.t()} | {:force_edit, []} | {:checktime, []} | {:new_buffer, []} | {:buffers, []} | {:buffer_next, []} | {:buffer_prev, []} | {:pin_tab, []} | {:unpin_tab, []} | {:move_tab_left, []} | {:move_tab_right, []} | {:lsp_info, []} | {:lsp_restart, []} | {:lsp_stop, []} | {:lsp_start, []} | {:extensions, []} | {:extension_update, []} | {:extension_update_all, []} | {:parser_restart, []} | {:safe_mode_status, []} | {:describe_command, []} | {:describe_command_named, [String.t()]} | {:describe_option, []} | {:describe_option_named, [String.t()]} | {:tutor, []} | {:agent_abort, []} | {:agent_new_session, []} | {:agent_clear_history, []} | {:agent_set_model, [String.t()]} | {:agent_pick_model, []} | {:agent_cycle_model, []} | {:agent_summarize, []} | {:agent_cycle_thinking, []} | {:tool_install_named, [String.t()]} | {:tool_uninstall_named, [String.t()]} | {:tool_update_named, [String.t()]} | {:tool_install, []} | {:tool_uninstall, []} | {:tool_update, []} | {:tool_list, []} | {:tool_manage, []} | {:view_warnings, []} | {:reload_highlights, []} | {:split_vertical, []} | {:split_horizontal, []} | {:window_close, []} | {:set_filetype, [String.t()]} | {:terminal, []} | {:goto_line, pos_integer()} | {:set, atom()} | {:setglobal, atom()} | {:substitute, String.t(), String.t(), [substitute_flag()]} | {:sort, range(), [sort_flag()]} | {:read, String.t()} | {:shell_command, String.t()} | {:global, String.t(), String.t()} | {:normal, range(), String.t()} | {:rename, String.t()} | {:dired, String.t() | nil} | {:unknown, String.t()}
Structured result of parsing a command-line string.
{:save, []}— write the current buffer to disk (:w){:force_save, []}— force-write, skipping mtime check (:w!){:quit, []}— close current tab or quit if last tab (:q){:force_quit, []}— force close tab or quit without saving (:q!){:quit_all, []}— quit the entire editor (:qa){:force_quit_all, []}— force quit the entire editor (:qa!){:abort_quit, []}— abort and quit with error exit code (:cq/:cquit){:save_quit, []}— save and close tab, or save and quit if last tab (:wq){:save_quit_all, []}— save all buffers and quit (:wqa){:edit, filename}— open a file (:e filename){:force_edit, []}— reload current buffer from disk (:e!){:new_buffer, []}— create a new empty buffer (:new/:enew){:buffers, []}— list open buffers (:buffers/:ls){:buffer_next, []}— move to next buffer (:bnext/:bn){:buffer_prev, []}— move to previous buffer (:bprev/:bp){:goto_line, n}— jump to line n (:<number>){:substitute, pattern, replacement, flags}—:%s/old/new/flags{:sort, range, flags}— sort lines in range (:sort/:%sort){:read, filename}— read file into buffer at cursor (:read/:r){:shell_command, command}— run shell command and show output (:!ls){:global, pattern, command}— run ex command on matching lines (:g/pat/cmd){:normal, range, keystrokes}— execute normal mode keystrokes on a range of lines (:normal){:unknown, raw}— unrecognised command
@type range() :: {:absolute, pos_integer(), pos_integer()} | :whole_buffer | :current_line | :last_line | :visual
Range specification for ex commands.
{:absolute, start_line, end_line}— absolute line numbers (1-indexed):whole_buffer— entire buffer (%):current_line— current line (.):last_line— last line in buffer ($){:visual}— visual selection ('<,'>)
@type sort_flag() :: :reverse | :numeric | :unique
Flags for :sort command (reverse, numeric, unique).
@type substitute_flag() :: :global | :confirm
Flags for :%s substitution.
Functions
Parses a command-line string (without the leading :) and returns a
parsed/0 value.
Examples
iex> Minga.Command.Parser.parse("w")
{:save, []}
iex> Minga.Command.Parser.parse("q!")
{:force_quit, []}
iex> Minga.Command.Parser.parse("e README.md")
{:edit, "README.md"}
iex> Minga.Command.Parser.parse("42")
{:goto_line, 42}
iex> Minga.Command.Parser.parse("w!")
{:force_save, []}
iex> Minga.Command.Parser.parse("e!")
{:force_edit, []}
iex> Minga.Command.Parser.parse("xyz")
{:unknown, "xyz"}