Repository navigation
[mini.ai] Any way to use multiple keys as a trigger for a text object? #2574
Contributing guidelines
Module(s)mini.ai QuestionHello! I'm trying to create a few custom text objects for Markdown files. I was hoping to use:
So if I have foo **bar** bazI could do I know I can create these with Thanks! |
Replies: 2 comments 8 replies
|
Not through the
local ai = require('mini.ai')
ai.setup({
custom_textobjects = {
mb = { '%*%*().-()%*%*' }, -- **bold**
mi = { '%f[%*]%*()[^%*].-()%*%f[^%*]' }, -- *italic*
mc = { '`()[^`]-()`' }, -- `code`
},
})
for _, ai_type in ipairs({ 'a', 'i' }) do
for _, id in ipairs({ 'mb', 'mi', 'mc' }) do
vim.keymap.set({ 'x', 'o' }, ai_type .. id, function() ai.select_textobject(ai_type, id) end)
end
endI tested it on You could also make |
|
Although using any fields in There are several approaches that solve the original problem here:
|
Although using any fields in
config.custom_textobjects(as suggested in this comment) may work, this is not guaranteed to be in the future (that's the reason I unmarked it as the answer). Textobject id is indeed only a single character by default, otherwise there is no good (robust yet not complex) way of knowing when to stop asking for user input.There are several approaches that solve the original problem here:
The way I'd recommend approaching the problem of "textobjects for markdown" is through buffer-local config created for files with
markdownfiletype. This is such a useful and common approach, that MiniMax has a dedicated example of it. It is for mini.surround', but a similar a…