cohama / lexima.vim

Auto close parentheses and repeat by dot dot dot...
996 stars 46 forks source link

Way to prevent autocomplete if Esc is pressed? #152

Open sainttttt opened 4 months ago

sainttttt commented 4 months ago

Hi! I'd like it so that if I press Esc (leaving insert mode) without entering another subsequent character, the autocomplete won't trigger. So for example just entering (<Esc> would end up with ( or ('<Esc> would give me (', but entering ('h<Esc> would give me ('h'). Would this be possible at all? I sort of have this functionality with some basic vim mappings as follows:

imap [<esc> <c-v>[<esc>
imap ['<esc> <c-v>[<c-v>'<esc>
imap ["<esc> <c-v>[<c-v>"<esc>
imap ']<esc> <c-v>'<c-v>]<esc>
imap "]<esc> <c-v>"<c-v>]<esc>

imap {<esc> <c-v>{<esc>
imap {'<esc> <c-v>{<c-v>'<esc>
imap {"<esc> <c-v>{<c-v>"<esc>
imap '}<esc> <c-v>'<c-v>}<esc>
imap "}<esc> <c-v>"<c-v>}<esc>

imap (<esc> <c-v>(<esc>
imap ('<esc> <c-v>(<c-v>'<esc>
imap ("<esc> <c-v>(<c-v>"<esc>
imap ')<esc> <c-v>'<c-v>)<esc>
imap ")<esc> <c-v>"<c-v>)<esc>

imap '<esc> <c-v>'<esc>
imap "<esc> <c-v>"<esc>

imap "" <c-v>"<c-v>"

But the main issue being is that for multiple char imappings, it doesn't show all the characters on the screen as you type, but just one at a time, which is a bit jarring. Any help would be appreciated.

Thanks!

cohama commented 3 months ago

I'm sorry for slow response. I was on vacation.

Do you mean the followings?

| char  | buffer |
------------------
| (     | (      |
| h     | (h     |
| <Esc> | (h)    |

In other words, if <Esc> pressed, close parens will be inserted?

sainttttt commented 1 month ago
| char  | buffer |
------------------
| (     | (      |
| h     | (h)    |
| char  | buffer |
------------------
| (     | (      |
| <Esc> | (      |

I mean something like this. So that if I enter another character it will trigger the autoclose, but if I just hit escape before entering another character, the autoclose doesn't happen. This is useful if I want to just insert a single ( or other autoclose character on a line.