hrsh7th / vim-vsnip-integ

vim-vsnip integrations to other plugins.
MIT License
127 stars 15 forks source link

Expand only with white space afterwards for conditional $VIM snippet #39

Open ghyatzo opened 3 years ago

ghyatzo commented 3 years ago

Hello,

I've been tinkering for a bit to allow some kind of context aware snippet expansion (similar to the context in UltiSnips). In my particular case i am trying to define some snippets that only get expanded while in a LaTeX math environment. I found that defining the snippet body as "${VIM: IsMathZone() ? \"<actual snippet>\" : \"<repeat prefix>\"} actually works.

The issue is that this kind of snippet only automatically expand upon selection (using mucomplete) only if i have a space afterwards.

Example: $test_snippet$ does not expand, $test_snippet $ does expand.

Similarly:

\[
    test_snippet
\]

does not expand, but

\[
    test_snippet<space>
\]

does.

Possibly related to #22, is there a way to decide how the auto expansion behaves?

hrsh7th commented 3 years ago

Agree. I think we should provide <Plug>(vsinp-integ-confirm) for insert mode key mapping.

let g:vsnip_integ_confirm_only_on_explicit_key_mapping = v:true

imap <CR> <Plug>(vsnip-integ-cofnrim)

In this setting, vim-vsnip-integ wont expand snippet when press the char that is not <CR>.

(I'm not native English speaker so it's helpful if you suggest config key name).

ghyatzo commented 3 years ago

What would be the difference from <Plug>(vsnip-expand) ?

Having a sort of "forced expand on completion" could be useful indeed. But i was thinking about a setting to be able to decide auto expansion behaviour, something like: let g:vsnip_integ_auto_expand_without_whitespace = v:true | v:false

Are the settings above already available? maybe i could test them.

PS: config names seems fine! I am not very sure about vsnip_integ_confirm_only_on_explicit_key_mapping as i am not really sure what it is supposed to do

hrsh7th commented 3 years ago

The vim-vsnip-integ will expand snippet automatically when the vim's CompleteDone autocmd.

vim fires CompleteDone even if the user press any chars.

So we provides <Plug>(vsnip-integ-confirm) that reserve next CompleteDone should be affect.

ghyatzo commented 3 years ago

I did not know! Thanks for explaining it! That sounds nice!