How to replicate HopChar2 in mini.jump2d? #205
-
|
Hello, I have been using the builtin jump2d opts, but I have found writing my own spotter challenging.
I have also found the builtin jump by query option to be great, but it is case-sensitive. Is there a way to make it case-insensitive? Thanks for the awesome plugin! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Hi!
My first suggestion is to look in direction of
It should be possible, although a bit hacky. Again, take a look at [this helper](this helper). Use I am not sure when I'd be able to write a full perfectly working example of |
Beta Was this translation helpful? Give feedback.
-
|
Ok, I've got time sooner than I thought. Try this snippet: local safe_getcharstr = function(msg)
vim.cmd('echon ' .. vim.inspect(msg))
-- Allow `<C-c>` to end input
local ok, res = pcall(vim.fn.getcharstr)
-- Clean command line
vim.cmd([[echo '' | redraw]])
-- Treat `<Esc>` or `<CR>` as cancel
if not ok or (res == '\27' or res == '\r') then return nil end
return res
end
local make_ignorecase_pattern = function(word)
local parts = {}
for i = 1, word:len() do
local char = word:sub(i, i)
if char:find('^%a$') then
-- Convert letter to a match both lower and upper case
char = '[' .. char:lower() .. char:upper() .. ']'
else
-- Escape non-letter characters
char = vim.pesc(char)
end
table.insert(parts, char)
end
return table.concat(parts)
end
local dummy_spotter = function() return {} end
require('mini.jump2d').setup({
spotter = dummy_spotter,
allowed_lines = { blank = false, fold = false },
hooks = {
before_start = function()
local first = safe_getcharstr("(mini.jump2d) Enter first character: ")
if first == nil then
MiniJump2d.config.spotter = dummy_spotter
return
end
local second = safe_getcharstr("(mini.jump2d) Enter second character: ")
if second == nil then
MiniJump2d.config.spotter = dummy_spotter
return
end
local pattern = make_ignorecase_pattern(first .. second)
MiniJump2d.config.spotter = MiniJump2d.gen_pattern_spotter(pattern)
end,
},
}) |
Beta Was this translation helpful? Give feedback.
Ok, I've got time sooner than I thought.
Try this snippet: