smjonas / inc-rename.nvim

Incremental LSP renaming based on Neovim's command-preview feature.
MIT License
637 stars 8 forks source link

Filling in the command line didn't work, but I fixed it #41

Closed pillmuncher closed 11 months ago

pillmuncher commented 11 months ago

This didn't work:

function()
    return ":IncRename " .. vim.fn.expand("<cword>")
end

It had no observable effect whatsoever.

vim.api.nvim_feedkeys() to the rescue:

function()
    local line = ":IncRename " .. vim.fn.expand("<cword>")
    vim.api.nvim_feedkeys(line, "n", true)
end

I don't know if it was my Neovim version (0.9.2) or some other plugin interfering, but now it's working.

smjonas commented 11 months ago

Glad it's working for you now! Does it also not work if you pass expr = true to vim.keymap.set?

pillmuncher commented 11 months ago

Yes, you're right. It was the expr = true. I'm using lazy.nvim as my plugin manager and accidentally had it written like this:

-- plugins/inc_rename.lua
return {
    "smjonas/inc-rename.nvim",
    opts = {},
    keys = {
        {
            "<leader>rn",
            function()
                return ":IncRename " .. vim.fn.expand("<cword>")
            end,
            desc = "[r]e[n]ame",
            mode = { "n" },
           { expr = true },  --  <------------------ 
        },
    },
}

Changing it to

           expr = true,

fixed it. My bad.