Mini pick - edit command history? #1926
-
Contributing guidelines
Module(s)mini.pick QuestionIn telescope there is a default keybind to edit a command from the command history list . Below is an excerpt from the telescope docs:
Is there a way to emulate this behavior when using mini pick's history command? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
There is no such action/mapping built-in, but it is possible to write custom picker that has one. Something like this: require('mini.pick').setup()
require('mini.extra').setup()
MiniPick.registry.command_history = function()
local edit_command = function()
local cur_match = MiniPick.get_picker_matches().current
cur_match = cur_match:gsub('^: ', ':')
vim.schedule(function() vim.api.nvim_input(cur_match) end)
return true
end
local opts = { mappings = { edit_command = { char = '<C-e>', func = edit_command } } }
MiniExtra.pickers.history({ scope = ':' }, opts)
end Now executing The reason it is not present by default is because it makes sense only for command and search history (while there are other history types present). But I've needed something like this myself several times, so maybe it is indeed useful to have built-in at least for those history types. I'll think about it. |
Beta Was this translation helpful? Give feedback.
-
thanks for your response, I just figured it out as well, this is my attempt: local history_mappings = {
execute = {
char = "<C-e>",
func = function()
local MiniPick = require("mini.pick")
local match = MiniPick.get_picker_matches()
if not match then
return
end
local value = type(match.current) == "table" and match.current.value or tostring(match.current)
value = value:gsub("^:+", "")
MiniPick.stop()
vim.schedule(function()
local cmd = ":" .. value
local keys = vim.api.nvim_replace_termcodes(cmd, true, false, true)
vim.api.nvim_feedkeys(keys, "n", false)
end)
end,
},
}
keymap("<leader>fch", function()
MiniExtra.pickers.history({ scope = ":" }, { mappings = history_mappings })
end, "Find command history") did not know about this registry thing, looks cleaner, i think il adapt mine to your style. thanks! |
Beta Was this translation helpful? Give feedback.
There is no such action/mapping built-in, but it is possible to write custom picker that has one. Something like this:
Now executing
:Pick command_history
will open picker with command history and custom<C-e>
mapping (it is…