smjonas / inc-rename.nvim

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

Amazing plugin #43

Closed 9mm closed 4 months ago

9mm commented 10 months ago

Hey I just found this, and it's exactly what I need but there would be one really awesome addition I think.

You have all the rest in place, and I feel like this might not be too difficult.

Is it possible to add other "modes" rather htan LSP rename? Specifically a simple find/replace in file? Everything else could remain exactly the same (dressing.nvim support, realtime updating, etc)

For example I'm using this keymap, and i actually made an issue in dressing.nvim on how to get it to update in realtime when doing a find/replace, and he directed me here.

-- find/replace word under cursor
-- vim.keymap.set('n', '<Leader>rn', [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]], { desc = 'Rename word under cursor'})
vim.keymap.set('n', '<Leader>rn', function()
  local current_word = vim.fn.expand("<cword>")
  vim.ui.input({
    prompt = 'Rename ' .. current_word .. ': ',
    default = current_word,
  }, function(new_name)
    if new_name then
      local escaped_word = vim.fn.escape(current_word, '\\/|&')
      local substitute_cmd = ":%s/\\<" .. escaped_word .. "\\>/" .. new_name .. "/g"
      vim.cmd(substitute_cmd)
    end
  end)
end, { desc = 'Rename word under cursor' })
smjonas commented 10 months ago

Hey, I'm really glad you enjoy the plugin! I believe noice.nvim should be able to handle your usecase😄 it might even be possible to use dressing for noice.nvim's window.