LunarWatcher / auto-pairs

Vim plugin, insert or delete brackets, parentheses, and quotes in pairs
MIT License
173 stars 6 forks source link

'Insert new indented line after Return' failed when used with vim-auto-popmenu #60

Closed echoonly closed 2 years ago

echoonly commented 2 years ago

When I used auto-pair with skywind3000/vim-auto-popmenu, the 'Insert new indented line after Return' features of auto-pair were no longer available. I hope to see results:

input:
function{|} (press <CR> at |)
output:
function{
    |
}

but I got this:

input:
function{|} (press <CR> at |)
output:
function{
|}

I use vim-plug to manage my plugin, If put the auto-pair in front of vim-auto-popmenu, like this:

Plug 'LunarWatcher/auto-pairs'
Plug 'skywind3000/vim-auto-popmenu'
let g:apc_enable_ft = {'*':1}

This feature will always be unavailable, but when reverse the order:

Plug 'skywind3000/vim-auto-popmenu'
let g:apc_enable_ft = {'*':1}
Plug 'LunarWatcher/auto-pairs'

This feature works fine when open vim, but if reload buffer with :e, or switch branch with git co, the feature fails again.

LunarWatcher commented 2 years ago

I'm not sure if there's any way to fix this here. skywind3000/vim-auto-popmenu forcibly maps <cr>. Not really sure why it fails intermittently, but when it does fail, if you :verbose imap <cr>, the keybind probably doesn't contain anything related to auto-pairs. Auto-pairs can't do its job if its functions aren't called.

There is some compatibility on our end, but if other plugins screw with the auto-pairs mappings after they're loaded... there's nothing that can be done. This is also an unfortunate downside of Vim not allowing several keybinds of the same type on the same key, particularly on central keys that a number of plugins actually use. cr and space being two of said keys does make the mapping a challenge. Might be more appropriate to raise an issue with skywind3000/vim-auto-popmenu and ask for a compatible CR mapping instead.

... quick digression, but I both see and don't see Vim's idea. You avoid conflicts, i.e. a plugin mapping, say, y, and both of them inserting their own characters, but Vim isn't multithreaded. Needing to manually create compound keybinds creates a lot of interesting compatibility issues between plugins, and a number of them could've been avoided if Vim supported multiple keybinds on the same key.

Anyway, like I said, I don't think there's anything auto-pairs can do here. If it's being steamrolled by vim-auto-popmenu, it's their fault.

echoonly commented 2 years ago

Thank you for the quick and exhaustive reply, I now figure out the reason for the failure, it is really not auto-pair's fault, auto-pair can not do anything, I will try to raise an issue with vim-auto-popmenu, thanks again.