VS代码段:如何使用变量连续两次变换
请参阅以下片段:
"srcPath":{
"prefix": "getSrcPath",
"body": [
"$TM_FILEPATH",
"${1:${TM_FILEPATH/(.*)src.(.*)/${2}/i}}",
"${TM_FILEPATH/[\\\\]/./g}"
]
},
第1-3行的输出是:
D:\root\src\view\test.lua
view\test.lua
D:.root.src.view.test.lua
如何获得诸如'view/test.lua'之类的输出?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试此片段:
。*src。|(\\\\)
将与所有内容匹配并包括... src \
路径信息。我们不会将其保存在捕获组中,因为我们没有在转换的替换部分中使用它。(\\\\)
在路径的其余部分中匹配任何\
- 需要g
标志以使它们全部获取。替换:
$ {1:+/}
,这意味着如果有一个捕获组1。代码>/
。请注意,我们在src \
之后不匹配其余路径,仅可能跟随它的\
。因此,不匹配其他路径零件只会允许它们保留在结果中。您在此方面接近了:
“ $ {tm_filepath/[\\\\\\]/\\ // g}”
只需用\\\\ > \\/。
Try this snippet:
.*src.|(\\\\)
will match everything up to and including the...src\
path information. We don't save it in a capture group because we aren't using it in the replacement part of the transform.The
(\\\\)
matches any\
in the rest of the path - need theg
flag to get them all.Replace:
${1:+/}
which means if there is a capture group 1 in.*src.|(\\\\)
then replace it with a/
. Note we don't match the rest of the path aftersrc\
only the\
's that might follow it. So, not matching those other path parts just allows them to remain in the result.You were close on this one:
"${TM_FILEPATH/[\\\\]/\\//g}"
just replace any\\\\
with\\/
.使用扩展 /a>您可以插入包含变量和多个发现操作的“摘要”。
使用键绑定:
目前只有键绑定或通过
Multi Command
(或类似)。将添加一个问题,以使前缀成为可能。另外,一些标准变量丢失了。
With the extension File Templates you can insert a "snippet" that contains a variable and multiple find-replace operations.
With a key binding:
At the moment only possible with a key binding or via
multi command
(or similar). Will add an issue to also make it possible by prefix.Also some of the standard variables are missing.