Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghyatzo opened this issue Dec 31, 2020 · 4 comments
Open

Comments

@ghyatzo
Copy link
Contributor

ghyatzo commented Dec 31, 2020

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
Copy link
Owner

hrsh7th commented Dec 31, 2020

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
Copy link
Contributor Author

ghyatzo commented Dec 31, 2020

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
Copy link
Owner

hrsh7th commented Dec 31, 2020

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
Copy link
Contributor Author

ghyatzo commented Dec 31, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants