Skip to main content

parse_describe_key_arg

Function parse_describe_key_arg 

Source
pub fn parse_describe_key_arg(s: &str) -> (Option<BindingMode>, &str)
Expand description

Parse a :describe-key argument that may carry a mode prefix.

Supports the six primary-mode prefix shorthands:

prefixmode
n_Normal
i_Insert
v_Visual
r_Replace
c_Command
s_Search

Returns (mode, chord_str):

  • mode is Some(BindingMode) when a prefix was recognised; chord_str is the remainder after stripping the x_ prefix.
  • When no prefix matches, mode is None and chord_str is the original input unchanged.

ยงExamples

use lattice_keymap::{BindingMode, parse_describe_key_arg};

let (mode, chord) = parse_describe_key_arg("n_j");
assert_eq!(mode, Some(BindingMode::Normal));
assert_eq!(chord, "j");

let (mode, chord) = parse_describe_key_arg("<C-w>j");
assert_eq!(mode, None);
assert_eq!(chord, "<C-w>j");

let (mode, chord) = parse_describe_key_arg("i_<C-n>");
assert_eq!(mode, Some(BindingMode::Insert));
assert_eq!(chord, "<C-n>");