1

I have auto_pairs_gentle plugin installed and vim-repeat but the bracket insertion automatically generated by auto_pairs_gentle are not repeated by the dot command.

e.g.: Suppose I insert f(x) by typing if(x<Esc> if I repeat the command using the dot command . the only things that is inserted is x

1
  • A quick way: replace "\<Left>" by "\<C-G>U\<Left>" in the source code. (Also, no need for vim-repeat)
    – husB
    Commented Jul 9, 2022 at 14:50

2 Answers 2

1

The tpope/vim-repeat plugin requires other plugins to support it by calling repeat#set, which auto-pairs-gentle does not.

Also, the plugin maps keys to <C-r>=…<cr> sequences in order to perform its actions. Some of those sequences involve moving the cursor (with Left or Right) or pressing Esc. Insert mode repeat cannot handle these in the way you expect because

The following keys are special.  They stop the current insert, do something,
and then restart insertion.  This means you can do something without getting
out of Insert mode.  This is very handy if you prefer to use the Insert mode
all the time, just like editors that don't have a separate Normal mode.  You
may also want to set the 'backspace' option to "indent,eol,start" and set the
'insertmode' option.  You can use CTRL-O if you want to map a function key to
a command.

(from :help ins-special-special) includes arrow keys, and obviously Esc ends the current insert.

The repeat . command normally literally repeats the last insert, so it doesn't handle <C-r>= well anyway: for example, try o<C-r>=localtime()<cr><cr><esc>....:echo localtime()<cr>. Note that the buffer fills up with the same line repeated, while the function's value has changed.

For cases like this, use a macro (:help q), which records the keystrokes literally.

1
  • Thanks! I believe I'll give auto-pairs a try. Commented Jun 30, 2022 at 18:59
1

In the source code of auto-pairs-gentle, we see that when an opening character is pressed, the mapping returned is

open.close."\<Left>"

ie, insert the opening char, followed by the closing char, and then move Left.

The arrow keys, including <Left> and <Right>, stop the current insert, move the cursor, and then restart insertion (as seen from :help ins-special-special).

This is why only the text inserted after the opening (, is saved into the . register.

One way to fix this is to replace "\<Left>" by "\<C-G>U\<Left>",
which, further down in that help page, says that

This makes it possible to use the cursor keys in Insert mode, without breaking the undo sequence and therefore using |.| (redo) will work as expected. Also entering a text like (with the "(" mapping from above):

Lorem ipsum (dolor

will be repeatable by using |.| to the expected

Lorem ipsum (dolor)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.