zed-industries/zed · error

Cannot save buffer with absolute path

Error message

Cannot save buffer with absolute path

What it means

Raised in the :w/<cmd> write handler register when the filename given in the vim command is an absolute path. Zed's save-with-name only supports relative paths inside a visible worktree (RelPath::new rejects absolute paths), so the write is refused with this error.

Source

Thrown at crates/vim/src/command.rs:496

            }
            return;
        }
        vim.update_editor(cx, |_, editor, cx| {
            let Some(project) = editor.project().cloned() else {
                return;
            };
            let Some(worktree) = project.read(cx).visible_worktrees(cx).next() else {
                return;
            };
            let path_style = worktree.read(cx).path_style();
            let Ok(project_path) =
                RelPath::new(Path::new(&action.filename), path_style).map(|path| ProjectPath {
                    worktree_id: worktree.read(cx).id(),
                    path: path.into_arc(),
                })
            else {
                // TODO implement save_as with absolute path
                Task::ready(Err::<(), _>(anyhow!(
                    "Cannot save buffer with absolute path"
                )))
                .detach_and_prompt_err(
                    "Failed to save",
                    window,
                    cx,
                    |_, _, _| None,
                );
                return;
            };

            if project.read(cx).entry_for_path(&project_path, cx).is_some()
                && action.save_intent != Some(SaveIntent::Overwrite)
            {
                let answer = window.prompt(
                    gpui::PromptLevel::Critical,
                    &format!(
                        "{} already exists. Do you want to replace it?",

View on GitHub (pinned to f4178619ac)

Solutions

  1. Save with a path relative to the worktree root
  2. Add the absolute path's directory as a worktree first
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/vim/src/command.rs:496 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/bb46405e457e6b1d. Report an issue: GitHub.