-
Notifications
You must be signed in to change notification settings - Fork 36
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
Visual mode snippet expansion #49
Comments
You can use this solution.
In this case, TM_SELECTED_TEXT behaves like When you want to behave like ultisnips, please heads up ultisnips solution (I don't know ultisnips's Thanks. |
Assuming these mapping imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>' I would expect the following:
My use case is selecting text visually, and wrap it in a snippet. |
Actually the UltiSnips From what I've gathered this is the logic: Is the selected text a snippet -> expand |
Hm... Indeed, My provided solution does not support the your case (e.g. wrap by OK, I will consider it. Now, I have a question. |
An example would be: aug -> augroup ${1:auc} ${2:test} $0 It then would work like this
With your plugin: I do this because I only have to change |
I think a good addition would be |
I might misunderstand what you said. Currently, IMO, I can't think your suggestion is useful... For example, the above case should be enough But I think we should implement visual snippet expansion as below behavior. {
"prefix": "wrap-tag",
"body": [
"<${1:tag}>",
"\t$TM_SELECTED_TEXT",
"</${1}>"
]
} If it implemented, we can wrap HTML element by select&expand |
The idea why I used It is a way to include another snippet. It isn't something that cannot be achieved otherwise but reduces copy&paste. |
How would I use |
Currently, vsnip can't expand So we should implement mapping that add the ability to choose snippet on visual-mode. |
Yes the nested placeholders work fine. I would want to use nested snippets,` like this:
Now I have Ideally |
Probably I understood what you want. Hm... I think it should not support vsnip itself. |
My idea was to use the visual selection as |
The select mode mapping I was looking for is this: func Reselect()
return "\<ESC>gv\<C-g>\<C-l>"
endfunc
smap <C-l> <C-g>o<ESC>a<C-r>=(vsnip#available(1) && !vsnip#expand()) ? '' : Reselect() <CR> |
I checked what UltiSnips does in the visual mode mapping: :call UltiSnips#SaveLastVisualSelection()<cr>gvs In vsnips this would mean that this saves the currently selected text in the current context and provides this along with the next expanded snippet as |
Which do you hope the I feel we talking about the two different feature. Or, we talking about just the one feature if so, I want to understand it. |
I think it's two features: a) use visual selection in snippets as a) this is how UltiSnips does it: #49 (comment) b) I figured out how to do this without any change of your plugin: |
I believe I'll test a bit and then report back. |
I got it working. Would you accept a PR which makes this feature discoverable and makes it easier to use it? Wouldn't change the API only add better support for the mappings. |
My random thought are
|
I have a somewhat working proof of concept. I'll create a PR when I've cleaned up. |
I've created two PRs one for |
I'm currently migrating from UltiSnips.
It is possible to use
$VISUAL
there which is the text which was selected when triggering the snippet:You select text, type an expansion keystroke, type the snippet and then again the keystroke (in insert)
Then the snippet is expanded and every appearance of
$VISUAL
is replaced. Not literally - usingVISUAL
as a placeholder was supported as well.Reading the docs from Microsoft
$TM_SELECTED_TEXT
should be the equivalent. But I haven't got it to work yet.Is this supported yet?
The text was updated successfully, but these errors were encountered: