echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.74k stars 179 forks source link

Alternative default config for 'mini.pairs' #835

Closed Sarctiann closed 4 months ago

Sarctiann commented 4 months ago

Contributing guidelines

Module(s)

mini.pairs

Description

I suggest this default configuration. I believe that is so much intuitive:

mappings = {
  -- Prevents the action if the cursor is just before any character or next to a "\".
  ["("] = { action = "open", pair = "()", neigh_pattern = "[^\\][%s%)%]%}]" },
  ["["] = { action = "open", pair = "[]", neigh_pattern = "[^\\][%s%)%]%}]" },
  ["{"] = { action = "open", pair = "{}", neigh_pattern = "[^\\][%s%)%]%}]" },
  -- This is default (prevents the action if the cursor is just next to a "\").
  [")"] = { action = "close", pair = "()", neigh_pattern = "[^\\]." },
  ["]"] = { action = "close", pair = "[]", neigh_pattern = "[^\\]." },
  ["}"] = { action = "close", pair = "{}", neigh_pattern = "[^\\]." },
  -- Prevents the action if the cursor is just before or next to any character.
  ['"'] = { action = "closeopen", pair = '""', neigh_pattern = "[^%w][^%w]", register = { cr = false } },
  ["'"] = { action = "closeopen", pair = "''", neigh_pattern = "[^%w][^%w]", register = { cr = false } },
  ["`"] = { action = "closeopen", pair = "``", neigh_pattern = "[^%w][^%w]", register = { cr = false } },
}
-- 24-04-25

However, it is just a suggestion.

Here is my config

(I will update this setup to get the more intuitive behavior to me)

echasnovski commented 4 months ago

Thanks for the suggestion!

Although this does look reasonable, this might have had some not obvious issues back when deciding 'mini.pairs' defaults (I think I tried this kind of neighborhood patterns and evidently decided against it). Plus I don't changing this many default values is worth it for this type of change.

So let's have it as a reference for alternative useful configurations.

Sarctiann commented 4 months ago

Here is my config

(I will update this setup to get the more intuitive behavior to me)