Closed mguellsegarra closed 4 months ago
Sure, this can be achieved by a proper neighborhood pattern. The exact pattern depends on how much characters you want to prevent (
to stop inserting the whole pair. Here is one example:
require('mini.pairs').setup({
mappings = {
['('] = { action = 'open', pair = '()', neigh_pattern = '[^\\][^(]' },
['['] = { action = 'open', pair = '[]', neigh_pattern = '[^\\][^[]' },
['{'] = { action = 'open', pair = '{}', neigh_pattern = '[^\\][^{]' },
},
})
For "(" this actually reads as "insert whole pair if left character is not \
and if right character is not (
". Similar to other opening characters.
Another approach is to take a more broad route of #835. It would be "insert whole pair if left character is not \
and if right character is whitespace". So it will not insert whole pair if directly before any non-whitespace character.
Hope it helps.
What a coincidence that just a few hours ago issue #835 was opened, addressing the same topic. Thank you once again, Evgeni, for all your work and for your quick response. I definitely love this community.
Background
First, I would like to express my appreciation for your work on the
mini.nvim
plugin — it's been a fantastic tool in my development setup. I have a question regarding a specific use case withmini.pairs
that I hope you can help me with.Query
I'm attempting to achieve more context-sensitive behavior with the auto-pair functionality, similar to how VSCode, IntelliJ, and other editors handle auto-pairing, especially in scenarios involving JavaScript arrow functions. Specifically, I'm looking to prevent the insertion of an unwanted closing parenthesis in situations like typing an opening parenthesis before
() =>
. The desired outcome is for it to result in(() =>
rather than()() =>
.Actual default behaviour
\|() => { }
(
(\|)() => { }
Desired behaviour
\|() => { }
(
(\|() => { }
I've experimented with various
neigh_pattern
configurations and other adjustments to address this issue, but so far, I haven't managed to achieve the desired behavior. I'm at a bit of a loss here. Could anyone offer some guidance or assistance?Thank you all!