Closed XXiaoA closed 4 months ago
I also noticed that. IncRename
kinda "blocks" the command history, since the moment you re-select the command, it's most likely invalid, preventing you from going further up in your history.
I think the solution would be to remove IncRename from the command history in general, since it's not really useful as a command you want to run again.
I also noticed that.
IncRename
kinda "blocks" the command history, since the moment you re-select the command, it's most likely invalid, preventing you from going further up in your history.I think the solution would be to remove IncRename from the command history in general, since it's not really useful as a command you want to run again.
Yeah, but are there any workaround to removs the command in history after renaming? I tried to do some tricks but failed eventually.
yep, I think I got it: use histdel
as a post_hook
for IncRename. This seems to work for me.
post_hook = function()
vim.fn.histdel("cmd", "^IncRename ")
end,
Thanks, it does work!
glad to hear it works, but nonetheless, I'd maybe not close the issue, since this problem should probably be fixed in the plugin?
Ummm, I don't think it's possible to fix the problem inside the plugin. That's because inc-rename use the command-preview
feature, which is not only the source of the problem, but also the "selling point" of inc-rename.
Maybe we could turn to @smjonas . If necessary, we could reopen the issue later.
why wouldn't it be possible? I mean, the plugin would pretty much only have to add the post_hook I just shared?
Oh, got it. Maybe whether add a hook is user's choice. Although sometimes it (this "problem") may be a obstacle, but sometimes it can be useful. For instance, if we wanna rename the current word to a word that I have renamed.
@chrisgrieser I sill had troubles with the hook you provided.
A workaround is to clear the history when entering the command line:
vim.api.nvim_create_augroup("IncRenameGroup", {})
vim.api.nvim_create_autocmd({ "CmdlineEnter" }, {
pattern = "*",
callback = function()
return vim.fn.histdel("cmd", "^IncRename")
end,
group = "IncRenameGroup",
})
Hi all, I am now deleting the command from the commandline history by default. If any of you feel like you really don't want this behavior, let me know + your reasoning. Unless that is the case, I won't add a separate option to reenable the old behavior for now.
Hi all, I am now deleting the command from the commandline history by default. If any of you feel like you really don't want this behavior, let me know + your reasoning. Unless that is the case, I won't add a separate option to reenable the old behavior for now.
Just found this issue because I actually use command-line history for :IncRename
.
I actually use the command line history a lot when mass renaming in multiple files in JavaScript. For example if I have a variable named foo
and I want to convert it into bar
in multiple files I would go to the variable definition, use my keybind for :IncRename
and press <C-f>
to open the history and press <Up>
until I found the last rename I did for that symbol.
I know it is not an optimized workflow and I could do it a lot faster with something like grep 'foo'
and cdo s/foo/bar/g
but it works well for me at the moment and would like be able to conserve it.
I actually haven't had issues with this command and the history, maybe because I disabled dressing.nvim
for inputs as I like to use <C-f>
for editing commands.
Though i am satisfied with the new commit, it is a breaking change to some extent.
use my keybind for :IncRename and press
to open the history
Off topic: you can press q:
in normal mode to do so.
@datwaft Thanks for letting me know, that seems like a valid workflow and the plugin should not prevent you from doing that.
@XXiaoA Since the new behavior can cause issues, would you be ok with letting users opt-in to delete the command from command-line history? I.e. making the old behavior the default and adding an option for the new behavior.
@smjonas IMO, reverting the commit and adding some hints in README is not bad. As we have done (https://github.com/smjonas/inc-rename.nvim/issues/40#issuecomment-1702399880), user just need to add three lines in their configuration.
@datwaft I have now reverted the change in the latest commit and will add the possibility to opt-in to the feature instead.
You can now set save_in_cmdline_history = false
to prevent the command from being saved to the cmdline history (works both when running the command as well as just previewing the rename, then cancelling the command)
Normally, we can use
up
anddown
key to rotate the command in history after typing:
. But if we usedIncRename
command we cannot do thathttps://github.com/smjonas/inc-rename.nvim/assets/62557596/4f5157bb-2865-497e-a944-71fe2cf3dac9