helix-editor/helix · error · anyhow::Error

Line number can only be `absolute` or `relative`.

Error message

Line number can only be `absolute` or `relative`.

What it means

LineNumber is the config enum behind Helix's line-number setting; its FromStr impl accepts only "absolute"/"abs" and "relative"/"rel" (case-insensitive). Any other string fails with this error when config.toml is parsed, because serde deserializes line-number through FromStr. The aliases exist precisely so short forms work, but nothing else does.

Source

Thrown at helix-view/src/editor.rs:894

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum LineNumber {
    /// Show absolute line number
    Absolute,

    /// If focused and in normal/select mode, show relative line number to the primary cursor.
    /// If unfocused or in insert mode, show absolute line number.
    Relative,
}

impl std::str::FromStr for LineNumber {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "absolute" | "abs" => Ok(Self::Absolute),
            "relative" | "rel" => Ok(Self::Relative),
            _ => anyhow::bail!("Line number can only be `absolute` or `relative`."),
        }
    }
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum GutterType {
    /// Show diagnostics and other features like breakpoints
    Diagnostics,
    /// Show line numbers
    LineNumbers,
    /// Show one blank space
    Spacer,
    /// Highlight local changes
    Diff,
    /// Indicator for when code actions are available
    CodeActionHint,
}

View on GitHub (pinned to 079a789e8c)

Solutions

  1. Set line-number = "relative" or "absolute" in config.toml ("rel"/"abs" also accepted).
  2. There is no hybrid mode on this key; relative-in-normal/absolute-in-insert behavior is a separate setting (relative-line-numbers style behavior is not configured through this value), so remove the invalid keyword.
  3. After editing, run :config-reload and confirm no error appears; check :log-open for the offending key path.

Example fix

# before (config.toml)
 line-number = "hybrid" # parse error

# after
 line-number = "relative"
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_line_number(s: &str) -> bool {
    matches!(s.to_lowercase().as_str(), "absolute" | "abs" | "relative" | "rel")
}

Type guard

fn parse_line_number(s: &str) -> Option<LineNumber> {
    match s.to_lowercase().as_str() {
        "absolute" | "abs" => Some(LineNumber::Absolute),
        "relative" | "rel" => Some(LineNumber::Relative),
        _ => None,
    }
}

Try / catch

match value.parse::<LineNumber>() {
    Ok(v) => editor.line_number = v,
    Err(_) => {
        eprintln!("config: line-number must be 'absolute' or 'relative', got '{value}'");
        editor.line_number = LineNumber::Absolute; // safe default
    }
}

Prevention

When it happens

Trigger: Setting line-number = "smart", "hybrid", or a typo like "relatve" in config.toml; deserializing a LineNumber from any non-enum string via code that uses .parse().

Common situations: Users migrating from other editors request "relative to cursor only in normal mode" styles (e.g. Vim's number+relativenumber hybrid) and guess a keyword; JSON/TOML typos; copying config snippets written for a different editor version that used different values.

Related errors


AI-assisted analysis of helix-editor/helix@079a789e8c (2026-08-16). Data as JSON: /api/errors/129cdd113728da70. Report an issue: GitHub.