diff --git a/book/src/registers.md b/book/src/registers.md index 2edf7e27a271..d3c44607beb1 100644 --- a/book/src/registers.md +++ b/book/src/registers.md @@ -43,7 +43,8 @@ Some registers have special behavior when read from and written to. | `_` | No values are returned | All values are discarded | | `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable | | `.` | Contents of the current selections | This register is not writable | -| `%` | Name of the current file | This register is not writable | +| `%` | Name of the current file, relative to Helix's current working directory | This register is not writable | +| `=` | Absolute path to the current file | This register is not writable | | `+` | Reads from the system clipboard | Joins and yanks to the system clipboard | | `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard | diff --git a/helix-view/src/register.rs b/helix-view/src/register.rs index d286a85ccafe..bf1d360d9d33 100644 --- a/helix-view/src/register.rs +++ b/helix-view/src/register.rs @@ -18,7 +18,8 @@ use crate::{ /// * Black hole (`_`): all values read and written are discarded /// * Selection indices (`#`): index number of each selection starting at 1 /// * Selection contents (`.`) -/// * Document path (`%`): filename of the current buffer +/// * Relative document path (`%`): filename of the current buffer, relative to Helix's current working directory +/// * Absolute document path (`%`): absolute path of the current buffer /// * System clipboard (`*`) /// * Primary clipboard (`+`) pub struct Registers { @@ -57,8 +58,16 @@ impl Registers { let text = doc.text().slice(..); Some(RegisterValues::new(doc.selection(view.id).fragments(text))) } - '%' => { - let path = doc!(editor).display_name(); + '%' | '=' => { + let doc = doc!(editor); + let path = match name { + '%' => doc.display_name(), + '=' => doc.path().map_or_else( + || crate::document::SCRATCH_BUFFER_NAME.into(), + |path| path.to_string_lossy(), + ), + _ => unreachable!(), + }; Some(RegisterValues::new(iter::once(path))) } '*' | '+' => Some(read_from_clipboard( @@ -80,7 +89,9 @@ impl Registers { pub fn write(&mut self, name: char, mut values: Vec) -> Result<()> { match name { '_' => Ok(()), - '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")), + '#' | '.' | '%' | '=' => { + Err(anyhow::anyhow!("Register {name} does not support writing")) + } '*' | '+' => { self.clipboard_provider.load().set_contents( &values.join(NATIVE_LINE_ENDING.as_str()), @@ -105,7 +116,9 @@ impl Registers { pub fn push(&mut self, name: char, mut value: String) -> Result<()> { match name { '_' => Ok(()), - '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support pushing")), + '#' | '.' | '%' | '=' => { + Err(anyhow::anyhow!("Register {name} does not support pushing")) + } '*' | '+' => { let clipboard_type = match name { '+' => ClipboardType::Clipboard, @@ -165,7 +178,8 @@ impl Registers { ('_', ""), ('#', ""), ('.', ""), - ('%', ""), + ('%', ""), + ('=', ""), ('+', ""), ('*', ""), ] @@ -192,7 +206,7 @@ impl Registers { true } - '_' | '#' | '.' | '%' => false, + '_' | '#' | '.' | '%' | '=' => false, _ => self.inner.remove(&name).is_some(), } }