Closed barrett-ruth closed 8 months ago
In 'mini.pairs' the neighborhood pattern is responsible to decide when inserted character expands into full pair. By default, '
has it such that single '
is inserted after any English letter (to be usable inside plain English text) and \
. This part won't change.
The most straightforward approach to solve this issue is to update neighborhood pattern for '
only in Python files. For that, create an 'after/ftplugin/python.lua' file inside your config directory and put there these lines:
if MiniPairs ~= nil then
MiniPairs.map_buf(0, 'i', "'", { action = 'closeopen', pair = "''", neigh_pattern = '[^\\].' })
end
This will create only a buffer-local mapping which will insert single '
only after \
. The downside is that it will insert double ''
after any letter also.
Closing as not planned.
Thank you for the quick response. I'm assuming I'm able to alter the regex to ignore solely f
?
For anyone looking, the above solution didn't work or wasn't satisfactory, so I added the following luasnip to my python files:
s('f', fmt('print(f{}{}{})', { c(1, { t("'"), t('"') }), i(2), rep(1) })),
Contributing guidelines
Module(s)
mini.pairs
Description
Support auto pairs for quotes ("'", '"') when typing python f-strings.
Neovim version
0.10.1
Steps to reproduce
nvim -nu minimal.lua
print(f'
Expected behavior
The quote is autopaired after the f-string.
Actual behavior
No auto-pairing is done.