patch 9.2.0677: Cannot clear the alternate file register #
Commit:
https://github.com/vim/vim/commit/9db6fe4b1793beda2b64c2980cb46a3664f75add
Author: Christoffer Aasted <[email protected]>
Date: Thu Jun 18 19:43:44 2026 +0000
patch 9.2.0677: Cannot clear the alternate file register #
Problem: Cannot clear the alternate file register #
Solution: Allow to clear it (Christoffer Aasted)
closes: #20537
Signed-off-by: Christoffer Aasted <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index b3448bf89..afcdca16b 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -1,4 +1,4 @@
-*change.txt* For Vim version 9.2. Last change: 2026 May 31
+*change.txt* For Vim version 9.2. Last change: 2026 Jun 18
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1334,19 +1334,19 @@ and ":put" commands and with CTRL-R.
feature}
*quote_#* *quote#*
6. Alternate file register "#
-Contains the name of the alternate file for the current window. It will
-change how the |CTRL-^| command works.
-This register is writable, mainly to allow for restoring it after a plugin has
-changed it. It accepts buffer number: >
- let altbuf = bufnr(@#)
- ...
- let @# = altbuf
-It will give error |E86| if you pass buffer number and this buffer does not
-exist.
-It can also accept a match with an existing buffer name: >
+Contains the |alternate-file| name for current window
+This register is writeable and changes which buffer CTRL-^ enters.
+A String is matched against existing buffer names, like |:buffer|: >
let @# = 'buffer_name'
-Error |E93| if there is more than one buffer matching the given name or |E94|
-if none of buffers matches the given name.
+Also supports using buffer number and |file-pattern|.
+
+Throws
+ |E86| when the buffer number does not exist
+ |E93| when more than one buffer matches
+ |E94| when none match
+
+Clear the register with empty String: >
+ let @# = ''
7. Expression register "= *quote_=* *quote=* *@=*
This is not really a register that stores text, but is a way to use an
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index a7778b5fe..a515589de 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt* For Vim version 9.2. Last change: 2026 Jun 13
+*version9.txt* For Vim version 9.2. Last change: 2026 Jun 18
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -52687,6 +52687,7 @@ Changed ~
- Rewrite the clientserver socketserver backend to use channels and JSON.
- During |complete()|-triggered completion, CTRL-N and CTRL-P are now subject
to insert-mode mappings.
+- It is possible to clear the alternate file register |quote#|.
*added-9.3*
diff --git a/src/register.c b/src/register.c
index 358fe6454..971cd7089 100644
--- a/src/register.c
+++ b/src/register.c
@@ -3152,6 +3152,12 @@ write_reg_contents_ex(
if (name == '#')
{
+ if (len == 0)
+ {
+ curwin->w_alt_fnum = 0; // clear altfile
+ return;
+ }
+
buf_T *buf;
if (VIM_ISDIGIT(*str))
diff --git a/src/testdir/test_registers.vim b/src/testdir/test_registers.vim
index bb1dd31f3..1bf3d6f60 100644
--- a/src/testdir/test_registers.vim
+++ b/src/testdir/test_registers.vim
@@ -396,6 +396,11 @@ func Test_set_register()
call assert_equal('Xfile_alt_1', getreg('#'))
call setreg('#', b2)
call assert_equal('Xfile_alt_2', getreg('#'))
+ call setreg('#', '')
+ call assert_equal('', getreg('#'))
+ call setreg('#', 'alt_1')
+ let @# = ''
+ call assert_equal('', getreg('#'))
let ab = 'regwrite'
call setreg('=', '')
diff --git a/src/version.c b/src/version.c
index 5aa9fde1c..d2e01aecb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 677,
/**/
676,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1waIuC-004SoF-P7%40256bit.org.