LunarWatcher / auto-pairs

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

Auto-pairs introduces a delay when pressing Ctrl-P in Telescope #35

Closed gregorias closed 3 years ago

gregorias commented 3 years ago

OS: Manjaro What vim?: Neovim 0.5

Describe the bug When you press <Ctrl-P> in Telescope, Telescope moves up one row but only after a noticeable delay. The delay seems to be only present when auto-pairs is installed.

Steps to reproduce

  1. Install Telescope
  2. Open Neovim in a directory with multiple files.
  3. Open Telescope (with :Telescope, for example)
  4. Press <C-P>

Telescope will move up one row but only after some time (~half a second). Without the auto-pairs plugin, <C-P> is instantaneous.

gregorias commented 3 years ago

The problems stems from auto-pairs imapping Ctrl-P at two places: https://github.com/LunarWatcher/auto-pairs/blob/1763e83c95394f772d942f93a409f3e16fcc91d3/autoload/autopairs.vim#L728-L737

The problem can be mitigated by unmapping those settings globally with

let g:AutoPairsMoveExpression = ""
let g:AutoPairsShortcutMultilineClose = ""

in init.vim.

I don't consider it a solution though. Ideally, those mappings could be defined per buffer and/or disabled per buffer, so that they can work in settings where their functionality is not needed.

LunarWatcher commented 3 years ago

That's a side-effect of the prefix I ended up using. Telescope declares <C-p>, auto-pairs declares <C-p><additional keybind>, meaning Vim will wait for further input after <C-p> to check if you meant <C-p> or <C-p>something else.

Making the maps buffer-specific isn't really hard, but this is a massive side-effect of #34 - I have no idea why Telescope triggers auto-pairs for you at all. In fact, auto-pairs doesn't normally load in popup buffers (or terminal buffers), which means no load, no auto-pairs, and no keybinds like that one load.

Also worth noting that you're using legacy maps - all the keybinds have a ctrl alternative, most of which start with <C-p> because I thought a prefix made sense. I'm probably gonna have to revisit the specifics, but as for telescope, this shouldn't happen because it shouldn't load in the first place. That's a discussion for #34, however

That being said, I can still add buffer variables for the mappings, but I'm not entirely sure about the actual practical usefulness of it if it's largely for a single buffer where it, again, shouldn't load.

gregorias commented 3 years ago

Using the <C-p> as the prefix is fine.

I think the issue stands regardless of #34. The reason for that is that if those mapping are not buffer specific but global, then it doesn't matter that auto-pairs doesn't function in telescope's prompt. Those mappings will still exist and every time I press <C-p>, Vim will wait for further input after <C-p>.

LunarWatcher commented 3 years ago

This isn't entirely fixed yet. It's done for all the keybinds, except g:AutoPairsShortcutMultilineClose, which I need to rework (#32) before I can make it a buffer variable. g:AutoPairsMoveExpression already has a buffer variable - see the documentation before setting it, though.

gregorias commented 3 years ago

g:AutoPairsMoveExpression already had a buffer variable - see the documentation before setting it, though.

Indeed, thanks. I didn't noticed it and assumed it was global.

LunarWatcher commented 3 years ago

That should be everything migrated, and respecting the new options -- there were a couple typos in the first round where the if statement checked the buffer variant, but the keybinds mapped the global variant :sweat_smile:

arashm commented 2 years ago

I had to disable all shortcuts one by one to fix this

vim.g.AutoPairsCompatibleMaps = 0
vim.g.AutoPairsMapBS = 1
vim.g.AutoPairsShortcutToggle = ""
vim.g.AutoPairsShortcutFastWrap = ""
vim.g.AutoPairsShortcutJump = ""
vim.g.AutoPairsShortcutBackInsert = ""
vim.g.AutoPairsMoveExpression = ""
vim.g.AutoPairsShortcutIgnore = ""
vim.g.AutoPairsShortcutToggleMultilineClose = ""
LunarWatcher commented 2 years ago

@arashm Auto-pairs shouldn't be starting in telescope buffers at all. If it's doing that again, this bug has regressed. If not, the standard conflict issue still remains, and that's a well-known problem I haven't bothered fixing because everything seems to conflict, and finding free keys in insert mode is a nightmare

arashm commented 2 years ago

@LunarWatcher This is VIM's normal behaviour, I believe. <C-p> is a global mapping that invokes Telescope's window. Since auto-pairs adds a <C-p><C-r> (or something else) mapping, when pressing <C-p>, vim adds a debounce/delay to give time to user to press other keys if needed. This is true for all mappings.

I think it would have been better not to have any default mappings and give the user the responsibility to define them if they need them.

anakimluke commented 1 year ago

For future reference:

I was experiencing the same delay when using a <c-p> mapping to invoke FZF . Adapting @arashm's answer to vim syntax solved the problem for me.

pooriajr commented 3 months ago

For anyone wanting a copy-paste solution in vim-script to unbind all the ctrl-p mappings:

let g:AutoPairsMoveCharacter = "" let g:AutoPairsCompatibleMaps = 0 let g:AutoPairsMapBS = 1 let g:AutoPairsShortcutToggle = "" let g:AutoPairsShortcutFastWrap = "" let g:AutoPairsShortcutJump = "" let g:AutoPairsShortcutBackInsert = "" let g:AutoPairsShortcutIgnore = "" let g:AutoPairsShortcutToggleMultilineClose = ""

maciej-ka commented 1 month ago

It's enough to unbind only these three in order to remove <c-p> lag

let g:AutoPairsShortcutToggle = ""
let g:AutoPairsShortcutJump = ""
let g:AutoPairsShortcutToggleMultilineClose = ""

Thanks for snippets @pooriajr, @arashm

LunarWatcher commented 1 month ago

There's also g:AutoPairsPrefix to change the prefix from ctrl-p