patch 9.1.1526: completion: search completion match may differ in case

Commit: 
https://github.com/vim/vim/commit/93c2d5bf7f01db594a3f5ebecbd5a31dfd411544
Author: Girish Palya <giris...@gmail.com>
Date:   Tue Jul 8 21:29:02 2025 +0200

    patch 9.1.1526: completion: search completion match may differ in case
    
    Problem:  completion: search completion match may differ in case
              (techntools)
    Solution: add "exacttext" to 'wildoptions' value (Girish Palya)
    
    This flag does the following:
    
    exacttext
          When this flag is present, search pattern completion
          (e.g., in |/|, |?|, |:s|, |:g|, |:v|, and |:vim|)
          shows exact buffer text as menu items, without
          preserving regex artifacts like position
          anchors (e.g., |/\<|). This provides more intuitive
          menu items that match the actual buffer text. However,
          searches may be less accurate since the pattern is not
          preserved exactly.
          By default, Vim preserves the typed pattern (with
          anchors) and appends the matched word. This preserves
          search correctness, especially when using regular
          expressions or with 'smartcase' enabled. However, the
          case of the appended matched word may not exactly
          match the case of the word in the buffer.
    
    fixes: #17654
    closes: #17667
    
    Signed-off-by: Girish Palya <giris...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 034c04f97..e71f0d635 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 9.1.  Last change: 2025 Jul 05
+*options.txt*  For Vim version 9.1.  Last change: 2025 Jul 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -9759,6 +9759,7 @@ A jump table for the options with a short description can 
be found at |Q_op|.
 <      'wildchar' also enables completion in search pattern contexts such as
        |/|, |?|, |:s|, |:g|, |:v|, and |:vim|.  To insert a literal <Tab>
        instead of triggering completion, type <C-V><Tab> or "  ".
+       See also |'wildoptions'|.
        NOTE: This option is set to the Vi default value when 'compatible' is
        set and to the Vim default value when 'compatible' is reset.
 
@@ -9926,6 +9927,20 @@ A jump table for the options with a short description 
can be found at |Q_op|.
        A list of words that change how |cmdline-completion| is done.
 
        The following values are supported:
+         exacttext     When this flag is present, search pattern completion
+                       (e.g., in |/|, |?|, |:s|, |:g|, |:v|, and |:vim|)
+                       shows exact buffer text as menu items, without
+                       preserving regex artifacts like position
+                       anchors (e.g., |/\<|).  This provides more intuitive
+                       menu items that match the actual buffer text.
+                       However, searches may be less accurate since the
+                       pattern is not preserved exactly.
+                       By default, Vim preserves the typed pattern (with
+                       anchors) and appends the matched word.  This preserves
+                       search correctness, especially when using regular
+                       expressions or with 'smartcase' enabled.  However, the
+                       case of the appended matched word may not exactly
+                       match the case of the word in the buffer.
          fuzzy         Use |fuzzy-matching| to find completion matches. When
                        this value is specified, wildcard expansion will not
                        be used for completion.  The matches will be sorted by
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index f53399587..340839f46 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2025 Jul 05
+*version9.txt*  For Vim version 9.1.  Last change: 2025 Jul 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41623,6 +41623,8 @@ Completion: ~
 - improved commandline completion for the |:hi| command
 - New option value for 'wildmode':
        "noselect"      - do not auto select an entry in the wildmenu
+       "exacttext"     - show exact matches in wildmenu with search
+                         completion
 - New flags for 'complete':
        "F{func}"       - complete using given function
        "F"             - complete using 'completefunc'
diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index d5730ab6b..75efe1c62 100644
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -4631,6 +4631,7 @@ copy_substring_from_pos(pos_T *start, pos_T *end, char_u 
**match,
     int                segment_len;
     linenr_T   lnum;
     garray_T   ga;
+    int                exacttext = vim_strchr(p_wop, WOP_EXACTTEXT) != NULL;
 
     if (start->lnum > end->lnum
            || (start->lnum == end->lnum && start->col >= end->col))
@@ -4646,12 +4647,17 @@ copy_substring_from_pos(pos_T *start, pos_T *end, 
char_u **match,
 
     segment_len = is_single_line ? (end->col - start->col)
                                : (int)STRLEN(start_ptr);
-    if (ga_grow(&ga, segment_len + 1) != OK)
+    if (ga_grow(&ga, segment_len + 2) != OK)
        return FAIL;
 
     ga_concat_len(&ga, start_ptr, segment_len);
     if (!is_single_line)
-       ga_append(&ga, '
');
+    {
+       if (exacttext)
+           ga_concat_len(&ga, (char_u *)"\n", 2);
+       else
+           ga_append(&ga, '
');
+    }
 
     // Append full lines between start and end
     if (!is_single_line)
@@ -4659,10 +4665,13 @@ copy_substring_from_pos(pos_T *start, pos_T *end, 
char_u **match,
        for (lnum = start->lnum + 1; lnum < end->lnum; lnum++)
        {
            line = ml_get(lnum);
-           if (ga_grow(&ga, ml_get_len(lnum) + 1) != OK)
+           if (ga_grow(&ga, ml_get_len(lnum) + 2) != OK)
                return FAIL;
            ga_concat(&ga, line);
-           ga_append(&ga, '
');
+           if (exacttext)
+               ga_concat_len(&ga, (char_u *)"\n", 2);
+           else
+               ga_append(&ga, '
');
        }
     }
 
@@ -4783,6 +4792,7 @@ expand_pattern_in_buf(
     int                compl_started = FALSE;
     int                search_flags;
     char_u     *match, *full_match;
+    int                exacttext = vim_strchr(p_wop, WOP_EXACTTEXT) != NULL;
 
 #ifdef FEAT_SEARCH_EXTRA
     has_range = search_first_line != 0;
@@ -4871,26 +4881,31 @@ expand_pattern_in_buf(
                    &word_end_pos))
            break;
 
-       // Construct a new match from completed word appended to pattern itself
-       match = concat_pattern_with_buffer_match(pat, pat_len, &end_match_pos,
-               FALSE);
-
-       // The regex pattern may include '\C' or '

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1uZEFW-00BG05-3q%40256bit.org.

Raspunde prin e-mail lui