{"record":{"id":"357e3a68813f75d2","repo":"helix-editor/helix","slug":"failed-to-push-to-register-name-clipboard-does","errorCode":null,"errorMessage":"Failed to push to register {name}: clipboard does not match register contents","messagePattern":"Failed to push to register (.+?): clipboard does not match register contents","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"helix-view/src/register.rs","lineNumber":122,"sourceCode":"\n    pub fn push(&mut self, name: char, mut value: String) -> Result<()> {\n        match name {\n            '_' => Ok(()),\n            '#' | '.' | '%' => Err(anyhow::anyhow!(\"Register {name} does not support pushing\")),\n            '*' | '+' => {\n                let clipboard_type = match name {\n                    '+' => ClipboardType::Clipboard,\n                    '*' => ClipboardType::Selection,\n                    _ => unreachable!(),\n                };\n                let contents = self\n                    .clipboard_provider\n                    .load()\n                    .get_contents(&clipboard_type)?;\n                let saved_values = self.inner.entry(name).or_default();\n\n                if !contents_are_saved(saved_values, &contents) {\n                    anyhow::bail!(\"Failed to push to register {name}: clipboard does not match register contents\");\n                }\n\n                saved_values.push(value.clone());\n                if !contents.is_empty() {\n                    value.push_str(NATIVE_LINE_ENDING.as_str());\n                }\n                value.push_str(&contents);\n                self.clipboard_provider\n                    .load()\n                    .set_contents(&value, clipboard_type)?;\n\n                Ok(())\n            }\n            _ => {\n                self.inner.entry(name).or_default().push(value);\n                Ok(())\n            }\n        }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-view/src/register.rs#L104-L140","documentation":"Pushing to '*' or '+' must append to the live system clipboard, so the code first verifies the current clipboard contents still equal what the register last stored (contents_are_saved). If another program (or a clipboard manager) changed the clipboard in between, appending would silently drop that foreign content, so it bails with \"clipboard does not match register contents\" instead of corrupting state.","triggerScenarios":"Yank/push to the '+' register, copy something in any other application (or let a clipboard manager mutate/normalize it), then push again to the same register; also triggered by clipboard managers that trim trailing newlines or re-encode text.","commonSituations":"Accumulating multiple selections into the clipboard across a few minutes while using the OS normally; Linux clipboard managers (clipit, klipper) or tmux/Wayland synchronization altering contents; whitespace/newline normalization by desktop environments between pushes.","solutions":["Overwrite instead of append: a plain write to '*'/'+ resets the register's view of the clipboard and clears the mismatch.","Accumulate in a named register (a-z) and copy the final result to '+' once, avoiding interleaved OS clipboard use.","Disable or configure clipboard managers that rewrite contents (trailing-newline trimming is a classic cause)."],"exampleFix":"# before\n yank to '+', copy elsewhere, push to '+' again  # mismatch error\n\n# after\n yank to 'a' repeatedly, then :set-register + \"#{a:content}\"  # single final copy","handlingStrategy":"fallback","validationCode":"fn clipboard_in_sync(registers: &Registers, name: char, provider: &ClipboardProvider) -> bool {\n    let Ok(current) = provider.load().get_contents(&match name { '+' => ClipboardType::Clipboard, _ => ClipboardType::Selection }) else { return false };\n    registers.read(name, editor)\n        .map(|vals| contents_are_saved(&vals.collect::<Vec<_>>(), &current))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match registers.push('+', value) {\n    Err(err) if err.to_string().contains(\"clipboard does not match\") => {\n        // foreign clipboard change: overwrite instead of append to resync\n        registers.write('+', vec![value])?;\n    }\n    other => other?,\n}","preventionTips":["Prefer a single write over repeated pushes to '*'/'+'.","Accumulate in named registers; copy to the clipboard once at the end.","Disable clipboard managers that trim newlines or rewrite contents between yanks."],"tags":["registers","clipboard","helix","rust","os-integration"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}