matchbufline and ignorecase/smartcase

17 views
Skip to first unread message

Salman Halim

unread,
Feb 19, 2024, 3:11:46 PMFeb 19
to Vim Users
Hello,

I'm using 64-bit GVim 9.1 patches 1-95 on Windows 10.

Is it possible to have matchbufline() observe 'ignorecase' and 'smartcase'? Currently, if I have 'ignorecase' and 'smartcase' set, it behaves as if only 'ignorecase' were on and gives me results that regular search, for example, don't:

Search for 'Unknown' where the file contains:

unknown
Unknown
UNKNOWN

Searching via n/N only finds the middle one (smartcase forces case matching) while matchbufline() matches all three.

I COULD, of course, stick a \c or \C in front of my pattern based on whether the pattern contains an upper-case character, but I'd rather find out whether there is a plan to make matchbufline() observer smartcase before I put in the workaround.

Thank you,

--
 
Salman

I, too, shall something make and glory in the making.

Yegappan Lakshmanan

unread,
Feb 19, 2024, 8:07:51 PMFeb 19
to vim...@googlegroups.com
Hi,

On Mon, Feb 19, 2024 at 12:11 PM Salman Halim <salma...@gmail.com> wrote:
>
> Hello,
>
> I'm using 64-bit GVim 9.1 patches 1-95 on Windows 10.
>
> Is it possible to have matchbufline() observe 'ignorecase' and 'smartcase'? Currently, if I have 'ignorecase' and 'smartcase' set, it behaves as if only 'ignorecase' were on and gives me results that regular search, for example, don't:
>

The matchbufline() function currently only supports the 'ignorecase'
option setting and
ignores the 'smartcase' setting.

Regards,
Yegappan

Salman Halim

unread,
Feb 19, 2024, 10:23:20 PMFeb 19
to vim...@googlegroups.com

On Mon, Feb 19, 2024 at 12:11 PM Salman Halim <salma...@gmail.com> wrote:
>
> Hello,
>
> I'm using 64-bit GVim 9.1 patches 1-95 on Windows 10.
>
> Is it possible to have matchbufline() observe 'ignorecase' and 'smartcase'? Currently, if I have 'ignorecase' and 'smartcase' set, it behaves as if only 'ignorecase' were on and gives me results that regular search, for example, don't:
>

The matchbufline() function currently only supports the 'ignorecase'
option setting and
ignores the 'smartcase' setting.

Regards,
Yegappan

Okay. I wasn't sure if it was in the plan. Thank you for explaining.

I wrote this function that does the job, but with a few defaults that I like:

1. Defaults to the current buffer
2. Uses the current search pattern if none is provided
3. Starts on line 1
4. Ends on the last line in the file (basically, defaults to the whole file)

If both ignorecase and smartcase are on and the pattern contains any uppercase letter, it temporarily turns off ignorecase to force the function to match case.

The function:

export def g:MatchBufLine( buf: any = bufnr(), pat: string = @/, lnum: any = 1, end: any = '$', dict: dict<any> = {} ): list<dict<any>>
  var matchCase: bool = false

  if ( &ignorecase && &smartcase && pat =~# '[A-Z]' )
    matchCase = true

    set noignorecase
  endif

  var result: list<dict<any>> = matchbufline( buf, pat, lnum, end, dict )

  if ( matchCase )
    set ignorecase
  endif

  return result
enddef

Hope someone else finds it useful.

Salman
Reply all
Reply to author
Forward
0 new messages