Vsnips
Vsnips copied to clipboard
请问Vsnips支持在snippet中使用 !p 吗?
ultisnips支持!p
在snippet中执行python代码,请问Vsnips支持这个功能吗?谢谢。
4.4.4 Global Snippets: *UltiSnips-globals*
Global snippets provide a way to reuse common code in multiple snippets.
Currently, only python code is supported. The result of executing the contents
of a global snippet is put into the globals of each python block in the
snippet file. To create a global snippet, use the keyword 'global' in place of
'snippet', and for python code, you use '!p' for the trigger. For example, the
following snippet produces the same output as the last example . However, with
this syntax the 'upper_right' snippet can be reused by other snippets.
------------------- SNIP -------------------
global !p
def upper_right(inp):
return (75 - 2 * len(inp))*' ' + inp.upper()
endglobal
snippet wow
${1:Text}`!p snip.rv = upper_right(t[1])`
endsnippet
------------------- SNAP -------------------
wow<tab>Hello World ->
Hello World HELLO WORLD
Python global functions can be stored in a python module and then imported.
This makes global functions easily accessible to all snippet files. Since Vim
7.4 you can just drop python files into ~/.vim/pythonx and import them
directly inside your snippets. For example to use
~/.vim/pythonx/my_snippets_helpers.py >
global !p
from my_snippet_helpers import *
endglobal
Vsnips的!p
功能需要用js
代码来写, 不能直接使用Python
代码
可以参考这里: https://github.com/corvofeng/Vsnips/wiki/Vsnips-%E7%94%A8%E6%88%B7%E8%87%AA%E5%AE%9A%E4%B9%89js%E5%87%BD%E6%95%B0
https://github.com/corvofeng/Vsnips/wiki/Vsnips-%E7%A4%BA%E4%BE%8B%E7%89%87%E6%AE%B5
如果你的函数是通用的, 可以考虑提PR加到这里, 让所有用户都能使用
https://github.com/corvofeng/Vsnips/blob/master/src/script_tpl.ts
目前Vsnip插件默认包含的snippet里面有大量是用!p的声明,而且似乎很多都无法使用,请问是我的设置问题还是这个预制snippet文件本身就不能用呢?
目前Vsnip插件默认包含的snippet里面有大量是用!p的声明,而且似乎很多都无法使用,请问是我的设置问题还是这个预制snippet文件本身就不能用呢?
!p
表示的是用 Python 解释器执行, VS Code 里面没法这么用, 需要重新编写一份 JavaScrip 代码用于执行, 类似
有哪些是你认为比较需要的呢, 可以考虑默认支持.