jiangmiao / auto-pairs

Vim plugin, insert or delete brackets, parens, quotes in pair
http://www.vim.org/scripts/script.php?script_id=3599
4.09k stars 373 forks source link

[Feature request] Escape next press #335

Open luiz00martins opened 3 years ago

luiz00martins commented 3 years ago

In most situations, I want auto-pairs to do exactly what it does: complete the pair for me. However, in some situations I actually want it to simply type the character.

As an example, if I type Sam's car, I will end up with "Sam's car'", forcing me to manually delete the last apostrophe. In the same vein, when I want to make a "[ ]" for neorg's todo list, I always end up with double spaces in the middle, again forcing me to delete it. There's also the off chance that I want to type another closing bracket inside of (), instead of moving to the outside.

In these situations, I don't necessarily want to toggle off auto-pairs. In the first case, I don't want it to complete the apostrophe, but I may want it to complete some brackets later. In the second one, I actually want it to complete the square bracket, just not the space.

It'd be nice if there was an option in which you could set a keybinding, say <c-e>, and it'd escape the next character for auto-pairs. So, for example, typing Sam<c-e>'s car would result in "Sam's car", typing [<c-e><space> would result in "[ ]", and typing (<c-e>) would result in "())".

LunarWatcher commented 3 years ago

' should already skip completion in a word. Can you verbose imap ' to make sure it's not being interfered with by another plugin? As for spaces, you can disable space remapping on a per-buffer basis. With an autocmd filetype, you can disable it for the todo file type,Iand save yourself an escape. I can dig up the variable when I've caught up with emails and notifications, but it's listed in the docs. It's not a bad idea to have a single-use escape though - it'd be easier than toggling for tiny edge-cases.

luiz00martins commented 3 years ago

It's not a bad idea to have a single-use escape though - it'd be easier than toggling for tiny edge-cases.

Exactly my thoughts.


Here's the output of verbose imap ':

i  '           *@<C-R>=AutoPairsInsert('''')<CR>
    Last set from ~/.local/share/nvim/site/pack/packer/start/auto-pairs/plugin/auto-pairs.vim line 453

Perhaps there's some option that I didn't set. Here's my current config:

vim.g.AutoPairsMapCR = 1
vim.g.AutoPairsMapCh = 0

Also, I found the g:AutoPairsMapSpace variable in /doc/AutoPairs.txt, but I'm not sure how (or if) I can use it to setup the mapping on a per buffer basis, since the variable is global.

LunarWatcher commented 3 years ago

Also, I found the g:AutoPairsMapSpace variable in /doc/AutoPairs.txt, but I'm not sure how (or if) I can use it to setup the mapping on a per buffer basis, since the variable is global.

Looks like I got confused by which repo did what. I've added a buffer variant to my fork, which should work. (Note that there's a bit of config migration). As a side-note, [ ] should insert just that, because ] is slightly "aggressive" and removes spacing, so it does "correct" itself.

The '-completion problem is a bit more of a mystery though, because it should work. Can you :echo g:AutoPairs? There should be a ['\v(^|\W)\zs''', '''', {'key': '''', 'mapclose': 1, 'multiline': 0}] in there

luiz00martins commented 3 years ago

I've added a buffer variant to my fork, which should work.

I'm changing to that fork immediately then :)

As a side-note, [ ] should insert just that, because ] is slightly "aggressive" and removes spacing, so it does "correct" itself.

Nice feature! Didn't knew about that one, as I always move outside of the brackets manually (with a custom insert mode keybind to move the cursor). Gonna start using the "move outside" bindings more then.

Can you :echo g:AutoPairs? There should be a ['\v(^|\W)\zs''', '''', {'key': '''', 'mapclose': 1, 'multiline': 0}] in there

Interestingly, there isn't:

{'```': '```', '`': '`', '"': '"', '{': '}', '''': '''', '(': ')', '''''''': '''''''', '[': ']', '"""': '"""'}
LunarWatcher commented 3 years ago

... That's because I did yet another dumb. I meant b:AutoPairsList, not g:AutoPairs. Corrected it while verifying locally, but that apparently didn't make it to my comment here. Today is clearly not my day - my bad!

luiz00martins commented 3 years ago

Bad on my part actually! I've just tested the apostrophe feature, and it works correctly, so Sam's car indeed outputs "Sam's car" (and b:AutoPairsList contains the list mentioned).

What most likely happened is that I was using a different auto closing plugin not long ago, and I thought this problem happened here when actually it happened on that other plugin. My bad!

LunarWatcher commented 3 years ago

No worries! Mistakes happen :)

I have to see how my workload balances out, but I'll try to take a look at the temporary toggle this evening. I'll mention this issue in the applicable commit when I get that far though.

LunarWatcher commented 3 years ago

This is now available (experimentally, for now) on the master branch, using <C-p><C-e>, because I suck at finding good keybinds that aren't compounds.

Need to make a few more changes, but I expect to deploy it to stable either later today or tomorrow.

luiz00martins commented 3 years ago

Already tested for a bit, and it seems to be working very well. Thanks for the feature!