jiangmiao/auto-pairs

Breaks '.'

srushti opened this issue · 15 comments

I'm not sure if this is even fixable (and I've faced similar issues with other pairing plugins), but could it possibly be made to work with '.'.
Currently if I type ''i[Hello world]' and then hit '.' I only get the 'Hello World' and not the brackets. I understand they work as different actions, but unfortunately vim users are used to thinking of an insert action as a repeatable command.
This becomes even more tricky if you use this as part of a 'cw' (change word) type command, because it forgets the changing part of the action.

Hello srushti,
i[hello world is be expand to i[]<LEFT>hello world, and the <LEFT> break the '.'
Currently I haven't a good solution. maybe you already know, you could use complex repeat(macro) qq to start recording a macro 'q', press q to stop recording then use @q to repeat the macro, and use @@ to repeat it again and again.

Yeah, I can use a macro, but I'd really rather not have to do that every time.
After trying out a bunch of different plugins which does what yours does (and each of them failing the '.' test in different ways) I came across AutoClose which seems to use a different approach, but also doesn't have any customisability.

It might be worth looking into vim repeat to accomplish this.

vim-repeat doesn't work for me,maybe I didn't configure vim-repeat write.
nmap . shows
n . * :<C-U>call <SNR>65_repeat(v:count)<CR>

I've been experiencing this problem fairly frequently lately - is this not fixed?

ptrin commented

@jiangmiao Is it necessary to use <LEFT>? Have you looked at getpos() and setpos() to move the cursor?

e.g.

function! MoveLeft()
    let l:curPos = getpos('.')
    call setpos('.',[curPos[0], curPos[1], curPos[2]-1, curPos[3]])
endfunction

@ptrin I've tested code. But it cannot work. The function action won't be recorded. The code (foo) will be repeated as ()foo

So for future reference, using Ctrl+V to circumvent auto-pairs does work...

As long as you are careful to not trigger auto-pairs by escaping each of these open parens/brackets with Ctrl+V they will land in the dot register properly.

Note: Starting from version 7.4.849 you can use <C-G>Cursor to move within a line and not break undo/redo

@chrisbra <C-g>U<cursor> maybe?
@jiangmiao Take a look at :help i_CTRL-G_U please

The issue should be fixed now.

Works great but only in nvim and not vim? Can anyone confirm?

@unphased Works fine in vim 7.4.1639. You need at least vim 7.4.849 i guess.

It seems like new lines within a pair breaks repeating with '.'. Has anyone else experienced this?

For example:

function moo() {
    |  <- cursor
}

Pressing '.' after that only enters a blank line. Any ideas?