-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
g:AutoPairsMapCR conflicts against coc.nvim #66
Comments
I'm aware this could happen in practice, and it's an unfortunate consequence of how Vim's mapping system is built. Essentially, only two maps of a given type for a given key can exist in a given mode; a global variant, and a buffer-only variant. For insert mode, that means you can have one global mapping for enter, and one buffer mapping for enter. The auto-pairs map and the coc map conflict. Now, jiangmiao's initial code made some assumptions about the integrity of I'm not entirely sure why Alternatively, it's related to
However, if At this time, I have no better suggestions than to make the else portion of the ternary be |
Thanks for all the details! Personally I've only encountered this issue when there are popup menus so may I know how you feel about tackling this case by case? For example, diff --git a/autoload/autopairs.vim b/autoload/autopairs.vim
index 173333f..25d858d 100644
--- a/autoload/autopairs.vim
+++ b/autoload/autopairs.vim
@@ -482,9 +482,9 @@ fun! autopairs#AutoPairsDetermineCRMovement()
endif
endfun
func! autopairs#AutoPairsReturn()
- if b:autopairs_enabled == 0 || b:AutoPairsIgnoreSingle
+ if b:autopairs_enabled == 0 || b:AutoPairsIgnoreSingle || pumvisible() || (exists('*coc#pum#visible') && coc#pum#visible())
let b:AutoPairsIgnoreSingle = 0
return ''
end
|
The thing is, that conflicts with people who don't want to make The beset way to solve it is to make sure there isn't a conflict, but auto-pairs also can't hijack global An option C of sorts to the trigger, actually, though that depends on the execution order of mappings; if vim can stop the mapping from executing in the middle to deal with the timer, it could consistently be stopping immediately after dispatching The third option is offering mappings compatible with various plugins by default, but as evidenced by coc.nvim recently introducing And of course, to add insult to injury, there's personal preference on top of that; some people might want to map So, sorting out the mapping itself in auto-pairs isn't an option, because that's what vimrcs are for, and adding the code you proposed introduces race conditions. Adding a variable for enabling the conditions does solve the user preference bit, but it doesn't solve the race condition. What would be nice is if Vim had facilities for dealing with conflicting mappings at the editor level rather than on a per-plugin with different practices basis, but that's massively complex onto itself, and I imagine a place where neovim and vim once again fork if it's attempted implemented, which itself isn't stonks. However, that's a pipedream and pipenightmare, and not something we need to think too much about when the problem remains |
... alternatively, if Vim had an equivalent of JavaScript's Conflict avoidance on keys is preferred as much as possible in Vim. Space and |
Understood. Thanks again for the explanation. Btw you mentioned 'I got used to ctrl-n and ctrl-y', was this talking about assigning them to e.g. |
Oh TIL Ctrl-y confirms current pum selection. That's indeed better! |
And ctrl-n goes to the next entry in the popup, yeah. They're default Vim keybinds for operating with the completion menu, so there's strictly speaking no need to remap There's also a mapping for going up in the list, but I keep forgetting what it is. The docs are probably more useful than me here. I also believe there's even more keybinds for interacting with the popup, but I just remember the ones I press daily. In either case, if manually invoking auto-pairs yourself in the mapping helps, that's still an option if you prefer |
That's Ctrl-p I believe. n = next, p = previous :D
Yup I just checked |
I'll just close this for now; I'll rather reopen if creative ideas for working around incompatible plugins, incompatible plugin versions, and async behavior appear. Until then, amending the map to include an explicit call to auto-pairs (+ disabling the built-in mapping), or preferring ctrl-y for completion insertion are viable workarounds. Imperfect solutions for an imperfect system |
For the record, via #72, I've figured out I was wrong. I assumed async because it sounds plausible for this bug, but I now highly doubt that. I'm unable to reproduce locally now, and it should work fine anyway. The c-y workaround is still solid, but my initial thought on the global vs buffer mappings are blatantly wrong. Buffer maps are always preferred, and auto-pairs includes global maps in its buffer map. That's why coc.nvim's remap works at all |
Leaving a final comment here: if someone is able to reproduce this again at any point in time, please consider leaving a comment (or opening a new issue) with the result of For instance, if
Run |
Good news; finally tracked down the source thanks to an issue from jiangmiao/auto-pairs. I was partly right. Async stuff causes bad behavior, but this is because both The only workaround is
I'll be expanding the documentation with this. |
Thank you!
And this apparently also fixed the conflict in Neo-Tree pop-up somehow.
I used to get 'buffer not modifiable' warnings after hitting Enter in
Neo-Tree fuzzy search pop-up (by default /), so I had to use
inoremap <expr> <CR> coc#pum#visible() ? coc#pum#confirm() : (&filetype == "neo-tree-popup" ? "\<CR>" : "\<CR>\<C-r>=autopairs#Keybinds#IgnoreInsertEnter('autopairs#AutoPairsReturn')\<CR>")
Now using your mapping alone everything works as expected :)
…On 4/2/23 00:33, Olivia (Zoe) wrote:
Good news; finally tracked down the source thanks to an issue from jiangmiao/auto-pairs.
I was partly right. Async stuff causes bad behavior, but this is because both |<SNR>|s execute in spite of the conditional in the first SNR. It objectively makes sense, just not in the way I thought
The only workaround is
|let g:AutoPairsMapCR = 0 inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<Plug>AutoPairsReturn" |
I'll be expanding the documentation with this.
—
Reply to this email directly, view it on GitHub <#66 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABCMP75L47CJY4H42EK2DBDWVUCJFANCNFSM55OWYPNQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
--
Frederick Zhang
PGP: 8BFB EA5B 4C44 BFAC C8EC 5F93 1F92 8BE6 0D8B C11D
|
Funny how things work out :) That said, you can also add |
Fallback <cr> map to to AutoPairsReturn because not using coc's formatting while typing Ref: LunarWatcher/auto-pairs#66
OS: Arch Linux (rolling)
What vim? (+ version): Neovim 0.7.2
Reproduced in other variants of Vim? (Optional): Yes. VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 28 2022 16:22:51)
Autopairs config (if applicable):
Describe the bug
After inserting a new pair, if coc.nvim's popup menu is visible, <CR> inserts a line above current line instead of selecting highlighted item from coc.nvim popup.
Steps to reproduce
mini.vim
:CocInstall coc-tsserver
src.js
nvim -u mini.vim src.js
let {us<CR>
sometimes
neoclide/coc.nvim#3031 and neoclide/coc.nvim#2204 are probably the same issue.
(Btw thanks for maintaining this project!)
The text was updated successfully, but these errors were encountered: