{"record":{"id":"b279b3cb69501569","repo":"helix-editor/helix","slug":"unknown-variable","errorCode":null,"errorMessage":"unknown variable '{}'","messagePattern":"unknown variable '(.+?)'","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"helix-view/src/expansion.rs","lineNumber":112,"sourceCode":"            \"selection\" => Some(Self::Selection),\n            \"selection_line_start\" => Some(Self::SelectionLineStart),\n            \"selection_line_end\" => Some(Self::SelectionLineEnd),\n            _ => None,\n        }\n    }\n}\n\n/// Expands the given command line token.\n///\n/// Note that the lifetime of the expanded variable is only bound to the input token and not the\n/// `Editor`. See `expand_variable` below for more discussion of lifetimes.\npub fn expand<'a>(editor: &Editor, token: Token<'a>) -> Result<Cow<'a, str>> {\n    // Note: see the `TokenKind` documentation for more details on how each branch should expand.\n    match token.kind {\n        TokenKind::Unquoted | TokenKind::Quoted(_) => Ok(token.content),\n        TokenKind::Expansion(ExpansionKind::Variable) => {\n            let var = Variable::from_name(&token.content)\n                .ok_or_else(|| anyhow!(\"unknown variable '{}'\", token.content))?;\n\n            expand_variable(editor, var)\n        }\n        TokenKind::Expansion(ExpansionKind::Unicode) => {\n            if let Some(ch) = u32::from_str_radix(token.content.as_ref(), 16)\n                .ok()\n                .and_then(char::from_u32)\n            {\n                Ok(Cow::Owned(ch.to_string()))\n            } else {\n                Err(anyhow!(\n                    \"could not interpret '{}' as a Unicode character code\",\n                    token.content\n                ))\n            }\n        }\n        TokenKind::Expand => expand_inner(editor, token.content),\n        TokenKind::Expansion(ExpansionKind::Shell) => expand_shell(editor, token.content),","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-view/src/expansion.rs#L94-L130","documentation":"expand() handles command-line tokens like %{name}; it resolves the inner name through Variable::from_name, which only knows the built-in variables: cursor_line, cursor_column, buffer_name, file_path_absolute, line_ending, current_working_directory, workspace_directory, language, selection, selection_line_start, selection_line_end. An unknown name produces \"unknown variable '{name}'\".","triggerScenarios":"Typing :echo %{linenumber} or any %{...} whose content is not exactly one of the eleven built-in names; passing unvalidated user input as a variable expansion; using a name added in a newer Helix version against an older build (or vice versa).","commonSituations":"Typos and snake_case mistakes (cursorLine vs cursor_line); assuming arbitrary editor state (like %{register} or %{mode}) is available as a variable; feature-drift between Helix versions where the variable list changed.","solutions":["Use one of the documented names: cursor_line, cursor_column, buffer_name, file_path_absolute, line_ending, current_working_directory, workspace_directory, language, selection, selection_line_start, selection_line_end.","Check book/src/command-line.md (the Variable list lives there and in Variable::VARIANTS) for your Helix version.","For shell/env data, use the shell expansion (%sh{...}) instead of an undefined variable."],"exampleFix":"# before\n :echo %{cursorline}\n\n# after\n :echo %{cursor_line}","handlingStrategy":"validation","validationCode":"let name = token_content; // text between %{ ... }\nif Variable::from_name(name).is_none() {\n    return Err(anyhow!(\n        \"unknown variable '{name}'; known: {:?}\",\n        Variable::VARIANTS.iter().map(|v| v.as_str()).collect::<Vec<_>>()\n    ));\n}\nexpand(editor, token)?;","typeGuard":"fn known_variable(s: &str) -> Option<Variable> {\n    Variable::from_name(s)\n}","tryCatchPattern":"match expand(editor, token) {\n    Ok(v) => { /* use v */ }\n    Err(err) if err.to_string().contains(\"unknown variable\") => {\n        // degrade gracefully: keep the literal text instead of failing the command\n        Ok(Cow::Borrowed(token.content))\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Validate variable names against Variable::VARIANTS before expansion.","Provide completion for %{...} in command-line UIs (VARIANTS exists for this).","Version-pin documentation; the variable list changes between Helix releases."],"tags":["expansion","command-line","helix","rust"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}