Comments (23)
I have a somewhat working proof of concept. I'll create a PR when I've cleaned up.
from vim-vsnip.
You can use this solution.
TM_SELECTED_TEXT;log|<Plug>(vsnip-expand)
In this case, TM_SELECTED_TEXT behaves like $VISUAL
or $TM_SELECTED_TEXT
.
When you want to behave like ultisnips, please heads up ultisnips solution (I don't know ultisnips's $VISUAL
workflow.)
Thanks.
from vim-vsnip.
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:
ihello<ESC>vb<C-l>
I entered stored 'hello' as $TM_SELECTED_TEXT
and I'm still in insert.
abc<C-l>
I expand the snippet 'abc' where $TM_SELECTED_TEXT
is 'hello'.
My use case is selecting text visually, and wrap it in a snippet.
Mostly selecting autocmd ...
and quickly wrap it in an augroup
with a snippet.
from vim-vsnip.
Actually the UltiSnips smap ... expand_or_jump
is more complicated.
From what I've gathered this is the logic:
Is the selected text a snippet -> expand
Is cursor in an expanded snippet -> jump
else -> set selected text to $VISUAL
from vim-vsnip.
Hm... Indeed, My provided solution does not support the your case (e.g. wrap by augroup
etc).
OK, I will consider it.
Now, I have a question.
When expanding snippet on visual mode by ultisnips, how choose snippet from many candidates?
My understanding is that has no timing to choose snippet in this case.
from vim-vsnip.
An example would be:
aug -> augroup ${1:auc} ${2:test} $0
auc -> hello
It then would work like this
aug<C-l>
the snippet expands and auc
is selected in select mode.
Pressing <C-l>
again would then insert the snippet ('hello').
With your plugin: aug<C-l>auc<C-l>
would be the same.
I do this because I only have to change auc
to change the snippet and it is just referenced inside of aug
instead of changing every snippet where I want to use it.
from vim-vsnip.
I think a good addition would be <plug>(vsnip-visual-expand)
where the visual selection is checked instead of the chars left to the cursor. Also the availability check would need to be updated/added for visual.
from vim-vsnip.
I might misunderstand what you said.
Currently, IMO, I can't think your suggestion is useful...
For example, the above case should be enough aug -> augroup hello ${2:test} $0
.
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 wrap-tag
snippet in visual-mode.
from vim-vsnip.
The idea why I used ${1:auc}
instead of hello
was that when I change hello
to hi
i would have to change both aug
and auc
. Of course auc
isn't just hello
and has many tabstops of its own.
autocmd ${1:${2:VimEnter} ${3:*}} $0
It is a way to include another snippet. It isn't something that cannot be achieved otherwise but reduces copy&paste.
from vim-vsnip.
vsnip has nested placeholder
feature so your recent example already supported now, I think.
{
"aug": {
"prefix": ["aug"],
"body": ["autocmd ${1:${2:VimEnter} ${3:*}} $0"]
}
}
This snippet works fine as you expected.
from vim-vsnip.
How would I use wrap-tag
?
Select it, press expand, type wrap-tag and press expand again?
from vim-vsnip.
Currently, vsnip can't expand wrap-tag
on visual-mode.
So we should implement mapping that add the ability to choose snippet on visual-mode.
from vim-vsnip.
Yes the nested placeholders work fine.
I would want to use nested snippets,` like this:
{
"aug": {
"prefix": ["aug"],
"body": ["something", "autocmd ${1:${2:VimEnter} ${3:*}} $0", "Else"]
},
"auc": {
"prefix": ["auc"],
"body": ["autocmd ${1:${2:VimEnter} ${3:*}} $0"]
}
}
Now I have "autocmd ${1:${2:VimEnter} ${3:*}} $0"
twice and changing it would require changing aug
and auc
.
Ideally aug
would have this body:
"body": ["something", "$auc", "Else"]
Where $auc
is replaced with the auc
snippet.
from vim-vsnip.
Probably I understood what you want.
Hm... I think it should not support vsnip itself.
But vsnip has vsnip#anonymous
API so I provide the way to enable it for you, please wait.
from vim-vsnip.
My idea was to use the visual selection as l:before_text
in vsnip#get_context()
.
from vim-vsnip.
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>
from vim-vsnip.
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 $TM_SELECTED_TEXT
.
from vim-vsnip.
Which do you hope the <Plug>(vsnip-select-on-visual)
or <Plug>(vsnip-expand-on-visual)
?
I feel we talking about the two different feature.
Or, we talking about just the one feature if so, I want to understand it.
from vim-vsnip.
I think it's two features:
a) use visual selection in snippets as $TM_SELECTED_TEXT
b) expand snippets from select mode
a) this is how UltiSnips does it: #49 (comment)
There is a mapping to store the text from visual mode and then use it for the next snippet.
b) I figured out how to do this without any change of your plugin:
#49 (comment)
from vim-vsnip.
I believe vsnip#selected_text('Text')
does what I'm looking for.
I'll test a bit and then report back.
from vim-vsnip.
I got it working.
I'm busy right now but I'll do a write up soon.
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.
from vim-vsnip.
My random thought are
-
It will be good to implement the 'b' feature in vsnip
- I think that' better to add
smap <Plug>(vsnip-expand)
but<Plug>(vsnip-expand-or-jump)
is not.
- I think that' better to add
-
I think the 'a' feature is very useful
- But I couldn't think good interface...
from vim-vsnip.
I've created two PRs one for a)
and one for b)
.
from vim-vsnip.
Related Issues (20)
- Selection could be broken when selection is exclusive HOT 2
- TAB jump no longer works after selecting completion with special chars HOT 8
- Beginner issue: unsure of the correct configuration
- How to prevent vsnip from jumping to the end of snippet when $0 isn't present in the snippet?
- Space within an element breaks the snippet flow HOT 1
- After expand, mode change to normal. (from select pooups) HOT 4
- Context (?) bug when adding text to a placeholder that is identical to text following the placeholder HOT 1
- Snippets not loaded under macro HOT 1
- Warn the user when snippets are loaded improperly due to json syntax error
- Duplicate lines after switching from Insert mode to Normal Mode
- Is possible run code on snippet spand.
- Highlight placeholders
- Support `scope` field HOT 1
- Completion menu does not show multiple snippets with same prefix
- Change vsnip_snippet_dir HOT 1
- Backslash in trigger
- Raise a clear warning message on startup when a snippets JSON file is invalid
- Placeholder more than 9 have issues
- expand wrong for `$` HOT 6
- Solution to vscode-go snippets not loading
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-vsnip.