Skip to content
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

[Feature request] Escape next press #335

Open
luiz00martins opened this issue Aug 25, 2021 · 9 comments
Open

[Feature request] Escape next press #335

luiz00martins opened this issue Aug 25, 2021 · 9 comments

Comments

@luiz00martins
Copy link

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
Copy link

' 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
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

... 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
Copy link
Author

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
Copy link

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 referenced this issue in LunarWatcher/auto-pairs Aug 27, 2021
Needs tests and a couple minor tweaks for automatically disabling, but should be good.

And in case the feature suggester reads this commit, sorry it took a couple days, my workload didn't balance out nicely :')
@LunarWatcher
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants