nvim-autopairs
nvim-autopairs copied to clipboard
Insert mode abbrev not triggered if have autopairs rule including spaces
Description
Say I have an abbreviation vim.keymap.set('!a', 'flase', 'false')
and I have the following rule set for autopairs:
-- Add spaces between parenthesis
Rule(' ', ' ')
:with_pair(function(opts)
local pairs_single_char = { '()', '[]', '{}' }
local pairs_double_char = { '/**/' }
if
vim.bo[opts.bufnr].ft == 'markdown'
and opts.line:match('^- ')
and utils.ft.markdown.in_normalzone()
then
pairs_single_char = { '()', '{}' }
end
return vim.tbl_contains(
pairs_single_char,
opts.line:sub(opts.col - 1, opts.col)
) or vim.tbl_contains(
pairs_double_char,
opts.line:sub(opts.col - 2, opts.col + 1)
)
end)
:with_del(function(opts)
return vim.fn.match(opts.line:sub(1, opts.col):reverse(),
[[\s\((\|[\|{\|\*\/\)]]) == 0
end)
After I inserting flase
and pressing space, the abbrev does not trigger, i.e. flase
does not turns into false
.
Removing the autopairs rule fixes this issue.
Mapping bug
N/A
Steps to reproduce
-
nvim -u minimal.lua
- Start insert mode, insert
flase
, then press space - Abbreviation not triggered
Minimal config
local tmp = '/tmp'
local data = tmp .. '/' .. (vim.env.NVIM_APPNAME or 'nvim')
local package_root = data .. '/site'
local clone_root = package_root .. '/pack/packages/start'
local clone_info = {
{
path = clone_root .. '/nvim-autopairs',
url = 'https://github.com/windwp/nvim-autopairs.git',
},
}
vim.fn.mkdir(clone_root, 'p')
vim.opt.pp:prepend(package_root)
vim.opt.rtp:prepend(package_root)
vim.opt.mousemoveevent = true
for _, info in ipairs(clone_info) do
if not vim.loop.fs_stat(info.path) then
vim.notify(
'cloning ' .. info.url .. ' to ' .. info.path,
vim.log.levels.INFO
)
vim.fn.system({ 'git', 'clone', info.url, info.path })
end
end
local npairs = require('nvim-autopairs')
local Rule = require('nvim-autopairs.rule')
npairs.setup()
npairs.add_rules({
-- Add spaces between parenthesis
Rule(' ', ' '):with_pair(function(opts)
local pairs_single_char = { '()', '[]', '{}' }
local pairs_double_char = { '/**/' }
if vim.bo[opts.bufnr].ft == 'markdown' and opts.line:match('^- ') then
pairs_single_char = { '()', '{}' }
end
return vim.tbl_contains(
pairs_single_char,
opts.line:sub(opts.col - 1, opts.col)
) or vim.tbl_contains(
pairs_double_char,
opts.line:sub(opts.col - 2, opts.col + 1)
)
end):with_del(function(opts)
return vim.fn.match(
opts.line:sub(1, opts.col):reverse(),
[[\s\((\|[\|{\|\*\/\)]]
) == 0
end),
})
vim.keymap.set('!a', 'flase', 'false')
Hi, is this project still maintained?
yes but not every day. sometime it is not maintain. i think you can use replace_endpair to trigger abbr.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.