freddiehaddad / feline.nvim

A minimal, stylish and customizable statusline, statuscolumn, and winbar for Neovim
GNU General Public License v3.0
289 stars 8 forks source link

bug(search_count): Vim:E54: Unmatched \( #92

Closed ilias777 closed 2 months ago

ilias777 commented 2 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.11.0-dev-219+gc37695a5d-Homebrew

Operating system/version

MacOS 14.5

Describe the bug

I use the search_count provider in feline. If I want to use a capturing group for search and replace, the error message Vim:E54: Unmatched \( appears.

In my example below I want to insert a description to my keymaps at once. So I startet the Visual Mode, select the region and press :s/ to start search and replace. I want to capture the whole text until ).

So I type:

It works, but the error message exist every time I tried to do something similar.

https://github.com/user-attachments/assets/bdf369c3-1aa8-49ab-b984-410ca4740498

Steps To Reproduce

  1. Start Visual Mode and select a region
  2. Go to command-line mode by pressing :
  3. Type: s/\( to start the capturing group. The error appears

Or without selecting a region in Visual Mode:

  1. Type: :%s/\( The error appears here to

Expected Behavior

No error by starting a capturing group.

Repro

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
    local lazyrepo = "https://github.com/folke/lazy.nvim.git"
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--branch=stable", -- latest stable release
        lazyrepo,
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

vim.g.mapleader = ","
vim.g.maplocalleader = ","

require("lazy").setup({
    {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
    },
    {
        "freddiehaddad/feline.nvim",
        config = function()
            require("feline").setup({
                components = {
                    active = {
                        {
                            {
                                provider = "search_count",
                                hl = "StatusLine",
                            },
                        }, -- left
                        {}, -- center
                        {}, -- right
                    },
                    inactive = { {} },
                },
            })
        end,
    },
})
freddiehaddad commented 2 months ago

Can you try this custom provider and see if it resolves your issue? I ran into something similar and fixed it in my personal config:

    provider = function()
    if vim.v.hlsearch == 0 then return '' end

    local ok, result =
        pcall(vim.fn.searchcount, { maxcount = 999, timeout = 250 })
    if not ok then return '' end
    if next(result) == nil then return '' end

    local denominator = math.min(result.total, result.maxcount)
    return string.format('[%d/%d]', result.current, denominator)
    end,

https://github.com/freddiehaddad/nvim/blob/606adf080c1196c989c575db45822082d565f48d/lua/plugins/feline.lua#L127-L145

If this works for you, I think I can patch the built-in provider so that the issue is fixed.

ilias777 commented 2 months ago

Yes! This works. Error doesn't exist with this function.

You can patch this 😊👍🏻