Search code examples
visual-studio-codecode-snippets

Snippet with configurable text


I want to make a code snippet where a part of the snippet text is substituted with a value that can be configured by the user.

Following this page I tried using an environment variable like

"${env:MYVALUE}"

and a configuration variable like

"${config:my.value}"

Both the environment variable and the user defined settings exist but they are not substituted. Are these variables not supported in snippets and if not is there some other way?


Solution

  • The variables from documentation mentioned in the question are only used in configuration files. Snippets have their own set of supported variables. Taken from the source these are:

    CURRENT_YEAR
    CURRENT_YEAR_SHORT
    CURRENT_MONTH
    CURRENT_DATE
    CURRENT_HOUR
    CURRENT_MINUTE
    CURRENT_SECOND
    CURRENT_DAY_NAME
    CURRENT_DAY_NAME_SHORT
    CURRENT_MONTH_NAME
    CURRENT_MONTH_NAME_SHORT
    SELECTION
    CLIPBOARD
    TM_SELECTED_TEXT
    TM_CURRENT_LINE
    TM_CURRENT_WORD
    TM_LINE_INDEX
    TM_LINE_NUMBER
    TM_FILENAME
    TM_FILENAME_BASE
    TM_DIRECTORY
    TM_FILEPATH
    BLOCK_COMMENT_START
    BLOCK_COMMENT_END
    LINE_COMMENT
    WORKSPACE_NAME
    

    Details can be found here.