]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0677: Cannot clear the alternate file register # master v9.2.0677
authorChristoffer Aasted <dezzadk@gmail.com>
Thu, 18 Jun 2026 19:43:44 +0000 (19:43 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 18 Jun 2026 19:45:38 +0000 (19:45 +0000)
Problem:  Cannot clear the alternate file register #
Solution: Allow to clear it (Christoffer Aasted)

closes: #20537

Signed-off-by: Christoffer Aasted <dezzadk@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/change.txt
runtime/doc/version9.txt
src/register.c
src/testdir/test_registers.vim
src/version.c

index b3448bf892392c8a0d8158753331d484b8846fae..afcdca16b097a10be6b11cac8cf60607505d0e0a 100644 (file)
@@ -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
index a7778b5fef7d414bec59bb1ba2a265c34b7f3aa8..a515589de52b2913139a50d4352db4c26e8e5779 100644 (file)
@@ -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*
index 358fe6454f56146c04e3c4eaba36f9484ae2d456..971cd70891aae2033f4bafad51d4de62b1e4b634 100644 (file)
@@ -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))
index bb1dd31f3e0261a1f574c650ae90247124074eb0..1bf3d6f6078783300ba2d1578bca2b4eef33b8d0 100644 (file)
@@ -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('=', '')
index 5aa9fde1c1e77f97d4a8f4d4243b6319e3f3967f..d2e01aecbce4b76888fa3576213dd8e5547c625c 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    677,
 /**/
     676,
 /**/