Insert comma after pair
sid-6581 opened this issue · comments
I just discovered this plugin and it's been working great so far! One thing that I have always wanted, which I didn't have in nvim-autopairs either, is the ability to insert a character after an autocompleted pair. One example is when adding a new nested item to a lua table:
{
{*} -- <-- After typing { I would like to be able to add a comma after the automatically added }
{ "altermo/ultimate-autopair.nvim", opts = {} },
},
In the example above I could use fastwarp and type {,<A-e>
which would move the }
to the left of the comma, but it would be nice if I could just type {,
and it would result in {},
with the cursor inside the braces.
Okay, how do you want it?
Do you want to be able to create non-pair mapps with the default profile?
And you need to implement the feature yourself, or should I add it as a feature?
Or do you just want a map that does it?
Like this one
local default=require'ultimate-autopair.profile.default.utils'
local utils=require'ultimate-autopair.utils'
local function create_map()
local m={}
m.doc='ultimate-autopair , map'
m.p=10
m.check=function (o)
if o.mode=='i' and o.key==',' and
utils.getsmartft(o)=='lua' and
o.line:sub(o.col-1,o.col-1)=='{' then
local pair,col,row=default.get_pair_and_end_pair_pos_from_start(o,o.col,true)
if not pair then return end
local node=utils.gettsnode(utils._get_o_pos(o,o.col-1))
if node and node:type()~='table_constructor' then return end
return utils.create_act{
{'j',row-o.row },{'home'},
{'l',col},
',',
{'k',row-o.row},{'home'},
{'l',o.col-1},
}
end
end
m.get_map=function (mode) if mode=='i' then return {','} end end
return m
end
require'ultimate-autopair'.init({
require'ultimate-autopair'.extend_default(your_own_config),
{
profile='raw',
create_map(),
}})
That worked great, thanks! I'm fine with implementing it myself like this, I just wasn't sure how to customize this plugin to that extent.
Then I can close this issue.