chrisgrieser / nvim-rip-substitute

Perform search and replace operations in the current buffer using a modern user interface and contemporary regex syntax.
MIT License
127 stars 7 forks source link

Bug: visual line mode not recognized #9

Closed mriva closed 1 month ago

mriva commented 1 month ago

Make sure you have done the following

Bug Description

When starting a sub with in visual line mode, the substitution defaults to normal mode instead of restricting to the range.

Relevant Screenshot

https://github.com/chrisgrieser/nvim-rip-substitute/assets/899235/6abcf94f-da69-4e66-af9b-07f0fdda7d0c

Screen recording taken with my setup, same behaviour happens with the minimal conf you provide in the last box of this form

To Reproduce

  1. select a range in visual line mode
  2. run this mapping: vnoremap <leader>s :lua require("rip-substitute").sub()<cr>
  3. box opens with full buffer substitute setup

neovim version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068

ripgrep version

❯ rg --pcre2-version --version
ripgrep 14.1.0

features:-simd-accel,+pcre2
simd(compile):+SSE2,-SSSE3,-AVX2
simd(runtime):+SSE2,+SSSE3,+AVX2

PCRE2 10.43 is available (JIT is available)

Minimal reproducible config

local spec = {
    {
        "chrisgrieser/nvim-rip-substitute",
        opts = {}, -- insert config here
        keys = {
            {
                "gs",
                function() require("rip-substitute").sub() end,
                mode = { "n", "x" },
                desc = "rip substitute",
            },
        },
    },
}
--------------------------------------------------------------------------------
vim.env.LAZY_STDPATH = "./nvim-repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro { spec = spec }
chrisgrieser commented 1 month ago

Well, you were really unlucky with your timing. That's a bug I accidentally introduced an hour ago, and which I fixed a few minutes after you submitted this bug report 🙈

update to the latest version and this should be fixed

mriva commented 1 month ago

Updated to f39e8c82250549431979d2d18eae3e6b97b46f04 but the issue remains.

chrisgrieser commented 1 month ago

are you sure? using f39e8c8, I cannot reproduce the issue with the minimal config.

chrisgrieser commented 1 month ago

ah, the issue is that you are using :lua require("rip-substitute").sub() in the RHS of your mapping. The : causes nvim to leave visual mode, which is why rip-substitute is then not able to pick up the correct mode anymore.

Use function() require("rip-substitute").sub() end as RHS of your keymap, and everything works correctly (And that is why we should actually use the minimal configs provided ;) )

mriva commented 1 month ago

Ah I see. Well I actually used the minimal config, but I was manually calling require("rip-substitute").sub() since I missed the binding provided and fell back to documentation (it was the only interface the README provided so I went with that).

I see you just added :RipSubstitute to the doc which also works.

Maybe function() require("rip-substitute").sub() end should be added to the README as well since the need for a wrapper function is not really clear.

Thanks for your help!

chrisgrieser commented 1 month ago

Ah, yes, it's fully written out in the Installation section, but not the Usage section. Added, thanks.