如何在Visual Studio代码段中获取基本目录? [英] How to get the base directory in visual studio code snippet?

查看:152
本文介绍了如何在Visual Studio代码段中获取基本目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio代码摘要中获取文件的当前目录。

I am trying to get the file current directory in a snippet for visual studio code.

VSCode具有变量 TM_DIRECTORY ,它是完整路径

例如:

{folder: "$TM_DIRECTORY"}

将替换为

{folder: "/Volumes/my-project-path/ParentFolder/MyFolder"}

但是我只想要 MyFolder

通常,我们可以使用按照文档中的指示进行转换。 Sublime Text以相同的方式工作。但就我所知,这段代码只是输出整个正则表达式。

Normally, we can use a transform as indicated in the docs. Sublime Text works in the same way. But for as much as I try, the snippet simply outputs the whole regex.

有人可以用神奇的变量/变换来回答吗? :)

Could someone answer with the magical variable/transform? :)

推荐答案

好,终于找到了。

$ {TM_DIRECTORY /^.+ \\ /(.*)$/$ 1 /} 给出基本目录。

我没有得到的部分是目录分隔符 / -> \\ /

The part I didn't get was the "double escape" of the directory separator / -> \\/.

这篇关于如何在Visual Studio代码段中获取基本目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆