@@ -1492,7 +1492,7 @@ mod cmd {
1492 #[derive(Clone)]
1492 #[derive(Clone)]
1493 pub struct TypableCommand {
1493 pub struct TypableCommand {
1494 pub name: &'static str,
1494 pub name: &'static str,
1495− pub alias: Option<&'static str>,
1495+ pub aliases: &'static [&'static str],
1496 pub doc: &'static str,
1496 pub doc: &'static str,
1497 // params, flags, helper, completer
1497 // params, flags, helper, completer
1498 pub fun: fn(&mut compositor::Context, &[&str], PromptEvent) -> anyhow::Result<()>,
1498 pub fun: fn(&mut compositor::Context, &[&str], PromptEvent) -> anyhow::Result<()>,
@@ -2092,252 +2092,252 @@ mod cmd {
2092 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2092 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2093 TypableCommand {
2093 TypableCommand {
2094 name: "quit",
2094 name: "quit",
2095− alias: Some("q"),
2095+ aliases: &["q"],
2096 doc: "Close the current view.",
2096 doc: "Close the current view.",
2097 fun: quit,
2097 fun: quit,
2098 completer: None,
2098 completer: None,
2100 TypableCommand {
2100 TypableCommand {
2101 name: "quit!",
2101 name: "quit!",
2102− alias: Some("q!"),
2102+ aliases: &["q!"],
2103 doc: "Close the current view.",
2103 doc: "Close the current view.",
2104 fun: force_quit,
2104 fun: force_quit,
2105 completer: None,
2105 completer: None,
2107 TypableCommand {
2107 TypableCommand {
2108 name: "open",
2108 name: "open",
2109− alias: Some("o"),
2109+ aliases: &["o"],
2110 doc: "Open a file from disk into the current view.",
2110 doc: "Open a file from disk into the current view.",
2111 fun: open,
2111 fun: open,
2112 completer: Some(completers::filename),
2112 completer: Some(completers::filename),
2114 TypableCommand {
2114 TypableCommand {
2115 name: "write",
2115 name: "write",
2116− alias: Some("w"),
2116+ aliases: &["w"],
2117 doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",
2117 doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",
2118 fun: write,
2118 fun: write,
2119 completer: Some(completers::filename),
2119 completer: Some(completers::filename),
2121 TypableCommand {
2121 TypableCommand {
2122 name: "new",
2122 name: "new",
2123− alias: Some("n"),
2123+ aliases: &["n"],
2124 doc: "Create a new scratch buffer.",
2124 doc: "Create a new scratch buffer.",
2125 fun: new_file,
2125 fun: new_file,
2126 completer: Some(completers::filename),
2126 completer: Some(completers::filename),
2128 TypableCommand {
2128 TypableCommand {
2129 name: "format",
2129 name: "format",
2130− alias: Some("fmt"),
2130+ aliases: &["fmt"],
2131 doc: "Format the file using a formatter.",
2131 doc: "Format the file using a formatter.",
2132 fun: format,
2132 fun: format,
2133 completer: None,
2133 completer: None,
2135 TypableCommand {
2135 TypableCommand {
2136 name: "indent-style",
2136 name: "indent-style",
2137− alias: None,
2137+ aliases: &[],
2138 doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)",
2138 doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)",
2139 fun: set_indent_style,
2139 fun: set_indent_style,
2140 completer: None,
2140 completer: None,
2142 TypableCommand {
2142 TypableCommand {
2143 name: "line-ending",
2143 name: "line-ending",
2144− alias: None,
2144+ aliases: &[],
2145 doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
2145 doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
2146 fun: set_line_ending,
2146 fun: set_line_ending,
2147 completer: None,
2147 completer: None,
2149 TypableCommand {
2149 TypableCommand {
2150 name: "earlier",
2150 name: "earlier",
2151− alias: Some("ear"),
2151+ aliases: &["ear"],
2152 doc: "Jump back to an earlier point in edit history. Accepts a number of steps or a time span.",
2152 doc: "Jump back to an earlier point in edit history. Accepts a number of steps or a time span.",
2153 fun: earlier,
2153 fun: earlier,
2154 completer: None,
2154 completer: None,
2156 TypableCommand {
2156 TypableCommand {
2157 name: "later",
2157 name: "later",
2158− alias: Some("lat"),
2158+ aliases: &["lat"],
2159 doc: "Jump to a later point in edit history. Accepts a number of steps or a time span.",
2159 doc: "Jump to a later point in edit history. Accepts a number of steps or a time span.",
2160 fun: later,
2160 fun: later,
2161 completer: None,
2161 completer: None,
2163 TypableCommand {
2163 TypableCommand {
2164 name: "write-quit",
2164 name: "write-quit",
2165− alias: Some("wq"),
2165+ aliases: &["wq", "x"],
2166 doc: "Writes changes to disk and closes the current view. Accepts an optional path (:wq some/path.txt)",
2166 doc: "Writes changes to disk and closes the current view. Accepts an optional path (:wq some/path.txt)",
2167 fun: write_quit,
2167 fun: write_quit,
2168 completer: Some(completers::filename),
2168 completer: Some(completers::filename),
2170 TypableCommand {
2170 TypableCommand {
2171 name: "write-quit!",
2171 name: "write-quit!",
2172− alias: Some("wq!"),
2172+ aliases: &["wq!", "x!"],
2173 doc: "Writes changes to disk and closes the current view forcefully. Accepts an optional path (:wq! some/path.txt)",
2173 doc: "Writes changes to disk and closes the current view forcefully. Accepts an optional path (:wq! some/path.txt)",
2174 fun: force_write_quit,
2174 fun: force_write_quit,
2175 completer: Some(completers::filename),
2175 completer: Some(completers::filename),
2177 TypableCommand {
2177 TypableCommand {
2178 name: "write-all",
2178 name: "write-all",
2179− alias: Some("wa"),
2179+ aliases: &["wa"],
2180 doc: "Writes changes from all views to disk.",
2180 doc: "Writes changes from all views to disk.",
2181 fun: write_all,
2181 fun: write_all,
2182 completer: None,
2182 completer: None,
2184 TypableCommand {
2184 TypableCommand {
2185 name: "write-quit-all",
2185 name: "write-quit-all",
2186− alias: Some("wqa"),
2186+ aliases: &["wqa", "xa"],
2187 doc: "Writes changes from all views to disk and close all views.",
2187 doc: "Writes changes from all views to disk and close all views.",
2188 fun: write_all_quit,
2188 fun: write_all_quit,
2189 completer: None,
2189 completer: None,
2191 TypableCommand {
2191 TypableCommand {
2192 name: "write-quit-all!",
2192 name: "write-quit-all!",
2193− alias: Some("wqa!"),
2193+ aliases: &["wqa!", "xa!"],
2194 doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).",
2194 doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).",
2195 fun: force_write_all_quit,
2195 fun: force_write_all_quit,
2196 completer: None,
2196 completer: None,
2198 TypableCommand {
2198 TypableCommand {
2199 name: "quit-all",
2199 name: "quit-all",
2200− alias: Some("qa"),
2200+ aliases: &["qa"],
2201 doc: "Close all views.",
2201 doc: "Close all views.",
2202 fun: quit_all,
2202 fun: quit_all,
2203 completer: None,
2203 completer: None,
2205 TypableCommand {
2205 TypableCommand {
2206 name: "quit-all!",
2206 name: "quit-all!",
2207− alias: Some("qa!"),
2207+ aliases: &["qa!"],
2208 doc: "Close all views forcefully (ignoring unsaved changes).",
2208 doc: "Close all views forcefully (ignoring unsaved changes).",
2209 fun: force_quit_all,
2209 fun: force_quit_all,
2210 completer: None,
2210 completer: None,
2212 TypableCommand {
2212 TypableCommand {
2213 name: "theme",
2213 name: "theme",
2214− alias: None,
2214+ aliases: &[],
2215 doc: "Change the theme of current view. Requires theme name as argument (:theme <name>)",
2215 doc: "Change the theme of current view. Requires theme name as argument (:theme <name>)",
2216 fun: theme,
2216 fun: theme,
2217 completer: Some(completers::theme),
2217 completer: Some(completers::theme),
2219 TypableCommand {
2219 TypableCommand {
2220 name: "clipboard-yank",
2220 name: "clipboard-yank",
2221− alias: None,
2221+ aliases: &[],
2222 doc: "Yank main selection into system clipboard.",
2222 doc: "Yank main selection into system clipboard.",
2223 fun: yank_main_selection_to_clipboard,
2223 fun: yank_main_selection_to_clipboard,
2224 completer: None,
2224 completer: None,
2226 TypableCommand {
2226 TypableCommand {
2227 name: "clipboard-yank-join",
2227 name: "clipboard-yank-join",
2228− alias: None,
2228+ aliases: &[],
2229 doc: "Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
2229 doc: "Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
2230 fun: yank_joined_to_clipboard,
2230 fun: yank_joined_to_clipboard,
2231 completer: None,
2231 completer: None,
2233 TypableCommand {
2233 TypableCommand {
2234 name: "primary-clipboard-yank",
2234 name: "primary-clipboard-yank",
2235− alias: None,
2235+ aliases: &[],
2236 doc: "Yank main selection into system primary clipboard.",
2236 doc: "Yank main selection into system primary clipboard.",
2237 fun: yank_main_selection_to_primary_clipboard,
2237 fun: yank_main_selection_to_primary_clipboard,
2238 completer: None,
2238 completer: None,
2240 TypableCommand {
2240 TypableCommand {
2241 name: "primary-clipboard-yank-join",
2241 name: "primary-clipboard-yank-join",
2242− alias: None,
2242+ aliases: &[],
2243 doc: "Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
2243 doc: "Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
2244 fun: yank_joined_to_primary_clipboard,
2244 fun: yank_joined_to_primary_clipboard,
2245 completer: None,
2245 completer: None,
2247 TypableCommand {
2247 TypableCommand {
2248 name: "clipboard-paste-after",
2248 name: "clipboard-paste-after",
2249− alias: None,
2249+ aliases: &[],
2250 doc: "Paste system clipboard after selections.",
2250 doc: "Paste system clipboard after selections.",
2251 fun: paste_clipboard_after,
2251 fun: paste_clipboard_after,
2252 completer: None,
2252 completer: None,
2254 TypableCommand {
2254 TypableCommand {
2255 name: "clipboard-paste-before",
2255 name: "clipboard-paste-before",
2256− alias: None,
2256+ aliases: &[],
2257 doc: "Paste system clipboard before selections.",
2257 doc: "Paste system clipboard before selections.",
2258 fun: paste_clipboard_before,
2258 fun: paste_clipboard_before,
2259 completer: None,
2259 completer: None,
2261 TypableCommand {
2261 TypableCommand {
2262 name: "clipboard-paste-replace",
2262 name: "clipboard-paste-replace",
2263− alias: None,
2263+ aliases: &[],
2264 doc: "Replace selections with content of system clipboard.",
2264 doc: "Replace selections with content of system clipboard.",
2265 fun: replace_selections_with_clipboard,
2265 fun: replace_selections_with_clipboard,
2266 completer: None,
2266 completer: None,
2268 TypableCommand {
2268 TypableCommand {
2269 name: "primary-clipboard-paste-after",
2269 name: "primary-clipboard-paste-after",
2270− alias: None,
2270+ aliases: &[],
2271 doc: "Paste primary clipboard after selections.",
2271 doc: "Paste primary clipboard after selections.",
2272 fun: paste_primary_clipboard_after,
2272 fun: paste_primary_clipboard_after,
2273 completer: None,
2273 completer: None,
2275 TypableCommand {
2275 TypableCommand {
2276 name: "primary-clipboard-paste-before",
2276 name: "primary-clipboard-paste-before",
2277− alias: None,
2277+ aliases: &[],
2278 doc: "Paste primary clipboard before selections.",
2278 doc: "Paste primary clipboard before selections.",
2279 fun: paste_primary_clipboard_before,
2279 fun: paste_primary_clipboard_before,
2280 completer: None,
2280 completer: None,
2282 TypableCommand {
2282 TypableCommand {
2283 name: "primary-clipboard-paste-replace",
2283 name: "primary-clipboard-paste-replace",
2284− alias: None,
2284+ aliases: &[],
2285 doc: "Replace selections with content of system primary clipboard.",
2285 doc: "Replace selections with content of system primary clipboard.",
2286 fun: replace_selections_with_primary_clipboard,
2286 fun: replace_selections_with_primary_clipboard,
2287 completer: None,
2287 completer: None,
2289 TypableCommand {
2289 TypableCommand {
2290 name: "show-clipboard-provider",
2290 name: "show-clipboard-provider",
2291− alias: None,
2291+ aliases: &[],
2292 doc: "Show clipboard provider name in status bar.",
2292 doc: "Show clipboard provider name in status bar.",
2293 fun: show_clipboard_provider,
2293 fun: show_clipboard_provider,
2294 completer: None,
2294 completer: None,
2296 TypableCommand {
2296 TypableCommand {
2297 name: "change-current-directory",
2297 name: "change-current-directory",
2298− alias: Some("cd"),
2298+ aliases: &["cd"],
2299 doc: "Change the current working directory (:cd <dir>).",
2299 doc: "Change the current working directory (:cd <dir>).",
2300 fun: change_current_directory,
2300 fun: change_current_directory,
2301 completer: Some(completers::directory),
2301 completer: Some(completers::directory),
2303 TypableCommand {
2303 TypableCommand {
2304 name: "show-directory",
2304 name: "show-directory",
2305− alias: Some("pwd"),
2305+ aliases: &["pwd"],
2306 doc: "Show the current working directory.",
2306 doc: "Show the current working directory.",
2307 fun: show_current_directory,
2307 fun: show_current_directory,
2308 completer: None,
2308 completer: None,
2310 TypableCommand {
2310 TypableCommand {
2311 name: "encoding",
2311 name: "encoding",
2312− alias: None,
2312+ aliases: &[],
2313 doc: "Set encoding based on `https://encoding.spec.whatwg.org`",
2313 doc: "Set encoding based on `https://encoding.spec.whatwg.org`",
2314 fun: set_encoding,
2314 fun: set_encoding,
2315 completer: None,
2315 completer: None,
2317 TypableCommand {
2317 TypableCommand {
2318 name: "reload",
2318 name: "reload",
2319− alias: None,
2319+ aliases: &[],
2320 doc: "Discard changes and reload from the source file.",
2320 doc: "Discard changes and reload from the source file.",
2321 fun: reload,
2321 fun: reload,
2322 completer: None,
2322 completer: None,
2324 TypableCommand {
2324 TypableCommand {
2325 name: "tree-sitter-scopes",
2325 name: "tree-sitter-scopes",
2326− alias: None,
2326+ aliases: &[],
2327 doc: "Display tree sitter scopes, primarily for theming and development.",
2327 doc: "Display tree sitter scopes, primarily for theming and development.",
2328 fun: tree_sitter_scopes,
2328 fun: tree_sitter_scopes,
2329 completer: None,
2329 completer: None,
2331 TypableCommand {
2331 TypableCommand {
2332 name: "vsplit",
2332 name: "vsplit",
2333− alias: Some("vs"),
2333+ aliases: &["vs"],
2334 doc: "Open the file in a vertical split.",
2334 doc: "Open the file in a vertical split.",
2335 fun: vsplit,
2335 fun: vsplit,
2336 completer: Some(completers::filename),
2336 completer: Some(completers::filename),
2338 TypableCommand {
2338 TypableCommand {
2339 name: "hsplit",
2339 name: "hsplit",
2340− alias: Some("sp"),
2340+ aliases: &["hs", "sp"],
2341 doc: "Open the file in a horizontal split.",
2341 doc: "Open the file in a horizontal split.",
2342 fun: hsplit,
2342 fun: hsplit,
2343 completer: Some(completers::filename),
2343 completer: Some(completers::filename),
@@ -2345,16 +2345,13 @@ mod cmd {
2347 pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
2347 pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
2348− let mut map = HashMap::new();
2350− for cmd in TYPABLE_COMMAND_LIST {
2348+ TYPABLE_COMMAND_LIST
2351− map.insert(cmd.name, cmd);
2351+ std::iter::once((cmd.name, cmd))
2352− if let Some(alias) = cmd.alias {
2352+ .chain(cmd.aliases.into_iter().map(move |&alias| (alias, cmd)))
2353− map.insert(alias, cmd);