auto-pairs icon indicating copy to clipboard operation
auto-pairs copied to clipboard

Is it possible to prevent the creation of the pair if there is a non whitespace character immediately after the cursor?

Open unphased opened this issue 8 years ago • 14 comments

This is inspired by sublime text. Try it, it will make the closing pair, but not if you are inserting text.

Is this possible?

unphased avatar Jul 13 '15 18:07 unphased

+1 from me. Especially useful when you have following scenario:

  if(a == b){

Now i want to add another condition

   if<position cursor here and type (>(a == b){

Currently it ends like this:

if()(a == b){

It would be nice if it would only insert the opening brace:

 if((a == b) && ...

RedX2501 avatar Jul 14 '15 08:07 RedX2501

+1. I'd like to have this option as well. Too many times I'm correcting existing code and end up like this.

ronakg avatar Aug 14 '15 04:08 ronakg

A workaround i sometimes am able to remember to use is vim-surround visual mode. it's handy

unphased avatar Aug 14 '15 06:08 unphased

I implemented this in my fork: https://github.com/eapache/auto-pairs

You can use that until @jiangmiao decides to merge my PR.

eapache avatar Sep 26 '15 14:09 eapache

+1 for this feature. Thanks!

nettrino avatar Nov 12 '15 01:11 nettrino

Thank you @eapache , it took me a long time of scratching my head and looking at the git log (which has really confusing date chronology) but I had already merged in your branch for months but only now I learned you have to g:AutoPairsOnlyWhitespace = 1 to put it into effect.

unphased avatar Jan 17 '16 18:01 unphased

(this is partially just a note to self for me to dig into eapache's changes and add these cases 😉)

  1. Any chance we can add an exception for when the offending following character happens to be the close side of another pair? For example if you type (' I'd like for it to insert ('') (where the cursor is now in the middle) but with this new fix it sees the inserted ) instead of a whitespace and so the ' does not get paired anymore and we're left with (') and now have to manually add the closing '
  2. extend this with some more cases. For example, if the immediately following character is a comma, I would like the pairing to proceed as before. For example, when writing a new argument to a function call (and I'm typing a function call or a string).

unphased avatar Jan 25 '16 02:01 unphased

thanks, @eapache Any ideas, why this feature wasn't merged yet?

gyermolenko avatar Apr 01 '16 12:04 gyermolenko

@gyermolenko just FYI I have since gone back to using jiangmiao's branch.

  1. see my Jan 24 comment, skipping triggering on nonwhitespace raises more problems. If I can get to it I would look into extending with those ideas to make the nonwhitespace behavior more friendly, and then merging it in
  2. new behavior just went in that fixes undo breakage. it's very nice, you can use . to repeat things typed in which triggers auto-pairs now.

unphased avatar Apr 01 '16 16:04 unphased

@unphased , Hi, thanks for reply. Although I have this adorable piece of vimrc inoremap <C-d> <Del> I still sometimes hate when brackets close at their will. So, I will try to live with (') and (, for some time )

gyermolenko avatar Apr 01 '16 19:04 gyermolenko

+1 On this one.

pbogut avatar May 23 '16 13:05 pbogut

Since I am interested by this feature, I am not sure to understand whether it has been merged or not ?

Thank you in advance.

BigfootN avatar Apr 16 '18 08:04 BigfootN

+1

khangal avatar Dec 04 '18 22:12 khangal

+1

kovasap avatar May 28 '19 22:05 kovasap