Dear Vim community,

On Saturday, 16 May 2026, Hernán Ibarra Mejia wrote:
> I like the recently added package helpcurwin, which displays help pages in the
> current window (rather than a split). However, there is a confirmation dialog
> that appears using `:HelpCurWin` when the current buffer is modified. This is
> annoying and inconsistent with the behaviour of other commands that have to
> solve the same problem—`:edit` being the prime example.

I attach a patch to solve this issue. It is my first time contributing to Vim
(apart from bug reports and trivial changes) so please tell me if I need to
correct something.

I noticed other issues with the package that I didn't address in this patch.

- The `-bar` option is on for HelpCurwin but this makes `:HelpCurwin |` not
  work, whereas `:help |` does. I think the `-bar` option should be removed.

- The new buffer is currently created with `keepalt noautocmd enew` but I don't
  know why noautocmd should be included, and I'd like for the alternate buffer
  to change so that after `:HelpCurwin` one can use CTRL-^ to go back

- The <Plug>HelpCurwin; mapping uses <cWORD> when I think it should use <cword>,
  since the latter is configurable and is supposed to match keywords.

I am happy to include fixes for these in my patch or open separate threads if
needed.

Best wishes,
Hernán

-- 
-- 
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/DIQ6EAZRY7K3.1SMU10I2CPBU0%40ibarramejia.com.
From bf4070913d9ff90ba9b1a83a4facb20e2e2f685b Mon Sep 17 00:00:00 2001
From: nagbu <[email protected]>
Date: Sat, 23 May 2026 16:21:54 +0100
Subject: [PATCH] helpcurwin: wrong behaviour if buffer is modified

Problem:  Package helpcurwin hardcodes confirmation dialog (in English)
          when buffer is modified; shows even if 'hidden' is set.
Solution: Defer buffer logic to :enew command, which handles 'hidden'
          and 'confirm' options (and for the latter, the dialog is
          translated if appropiate).

If there are no help pages matching the argument, HelpCurwin now opens
the main help page and shows an error (breaking change: before
HelpCurwin would not open any help page).

Signed-off-by: nagbu <[email protected]>
---
 runtime/doc/tips.txt                          |  3 --
 .../opt/helpcurwin/autoload/helpcurwin.vim    | 51 +++++++++----------
 .../dist/opt/helpcurwin/doc/helpcurwin.txt    |  3 +-
 .../dist/opt/helpcurwin/plugin/helpcurwin.vim |  9 +++-
 4 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/runtime/doc/tips.txt b/runtime/doc/tips.txt
index 9dde7dc41..2d4b9703e 100644
--- a/runtime/doc/tips.txt
+++ b/runtime/doc/tips.txt
@@ -556,9 +556,6 @@ with: >vim
 After it has loaded:
 - The command `:HelpCurwin` {subject} can be used to open help in the current
   window.
-- If the current window contains a modified buffer, the plugin asks for
-  confirmation before replacing it.  If confirmed, the buffer becomes
-  hidden |hidden-buffer|.
 - The help file, |helpcurwin.txt|, will be available and describes the plugin
   in more details.
 
diff --git a/runtime/pack/dist/opt/helpcurwin/autoload/helpcurwin.vim b/runtime/pack/dist/opt/helpcurwin/autoload/helpcurwin.vim
index 52a2d4f7c..a53343757 100644
--- a/runtime/pack/dist/opt/helpcurwin/autoload/helpcurwin.vim
+++ b/runtime/pack/dist/opt/helpcurwin/autoload/helpcurwin.vim
@@ -5,38 +5,35 @@ vim9script
 # Maintainer:   The Vim Project <https://github.com/vim/vim>
 # Last change:  2025 Dec 02
 
-export def Open(subject: string): void
+export def Open(subject: string): string
+
+  if &buftype != 'help'
+    const old_bufnr: number = bufnr()
+    const old_modified: bool = &modified
 
-  const HELPCURWIN: func = (): string => {
-  if !getcompletion(subject, 'help')->empty() || subject->empty()
-    if &buftype != 'help'
-      execute 'silent noautocmd keepalt enew'
-      setlocal buftype=help noswapfile
-    endif
-  endif
-  return $'help {subject}'
-  }
-
-  var contmod: bool = true
-  if &modified
-    echohl MoreMsg
-    echo $'Buffer {bufname()} is modified - continue? (y/n)'
-    echohl None
-    contmod = (getcharstr() == 'y')
-  endif
-  if contmod
     try
-      execute HELPCURWIN()
-    catch
-      echohl Error
-      # {subject} invalid - Echo 'helpcurwin: E149:' (omit 'Vim(help):')
-      echo $'helpcurwin: {v:exception->substitute("^[^:]\+:", "", "")}'
-      echohl None
+      noautocmd keepalt enew
+    catch /^Vim(enew):E37:/ # No write since last change
+      return v:exception
     endtry
-  else
-    echo $'Aborted opening in current window, :help {subject}'
+
+    # if &confirm then :enew never errors, but user may cancel
+    if (old_modified && old_bufnr == bufnr())
+      return ""
+    endif
+
+    setlocal buftype=help noswapfile
   endif
 
+  try
+    execute "help" subject
+  catch /^Vim(help):E149:/ # No help found
+    silent help
+    return v:exception
+  endtry
+
+  return ""
+
 enddef
 
 # vim: ts=8 sts=2 sw=2 et
diff --git a/runtime/pack/dist/opt/helpcurwin/doc/helpcurwin.txt b/runtime/pack/dist/opt/helpcurwin/doc/helpcurwin.txt
index 2bca8d034..b90a649e0 100644
--- a/runtime/pack/dist/opt/helpcurwin/doc/helpcurwin.txt
+++ b/runtime/pack/dist/opt/helpcurwin/doc/helpcurwin.txt
@@ -38,7 +38,8 @@ The underlying `:def` function may also be used, for example: >vim
 	:vim9cmd helpcurwin#Open('version9.2')
 <
 This may be useful from other scripts where you want to bring up help on
-{subject} in the current window.
+{subject} in the current window. The function returns an error message if
+there are any errors, or an empty string otherwise.
 
 
 ==============================================================================
diff --git a/runtime/pack/dist/opt/helpcurwin/plugin/helpcurwin.vim b/runtime/pack/dist/opt/helpcurwin/plugin/helpcurwin.vim
index e9960954a..57d91a595 100644
--- a/runtime/pack/dist/opt/helpcurwin/plugin/helpcurwin.vim
+++ b/runtime/pack/dist/opt/helpcurwin/plugin/helpcurwin.vim
@@ -7,8 +7,13 @@ vim9script
 
 import autoload '../autoload/helpcurwin.vim'
 
-command -bar -nargs=? -complete=help HelpCurwin helpcurwin.Open(<q-args>)
+command -bar -nargs=? -complete=help HelpCurwin {
+  var errstr: string = helpcurwin.Open(<q-args>)
+  if (!errstr->empty())
+    echoerr $'helpcurwin:{errstr}'
+  endif
+}
 
-nnoremap <Plug>HelpCurwin; <ScriptCmd>helpcurwin.Open(expand('<cWORD>'))<CR>
+nnoremap <Plug>HelpCurwin; <Cmd>execute "HelpCurwin" expand('<cWORD>')<CR>
 
 # vim: ts=8 sts=2 sw=2 et
-- 
2.54.0

Raspunde prin e-mail lui