How to get the base directory in visual studio code snippet?

北慕城南 提交于 2020-05-25 11:31:52

问题


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

VSCode has a variable: TM_DIRECTORY, which is the fullpath.

eg:

{folder: "$TM_DIRECTORY"}

would be replaced by

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

But I want only MyFolder.

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? :)


回答1:


Ok, finally found it.

${TM_DIRECTORY/^.+\\/(.*)$/$1/} gives the base directory.

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



来源:https://stackoverflow.com/questions/48366014/how-to-get-the-base-directory-in-visual-studio-code-snippet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!