Ask Your Question
1

How can you put plain text immediately adjacent to variables (eliminating the need for any whitespace) when utilizing VS Code User Snippets?

asked 2021-05-17 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-12-01 20:00:00 +0000

scrum gravatar image

You can use the ${} notation to insert the variable name directly next to the plain text. For example, instead of using "${1:variable} " (with a space at the end), you can use "${1:variable}" (with no space) to eliminate the whitespace. Here's an example:

{
    "Print": {
        "prefix": "print",
        "body": [
            "console.log('${1:message}: ${2}'${3:, variable})"
        ],
        "description": "Print message with optional variable"
    }
}

This snippet allows you to print a message with an optional variable. If you don't include a variable, there will be no space between the colon and the closing quote. If you do include a variable, it will be immediately adjacent to the closing quote.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-17 11:00:00 +0000

Seen: 9 times

Last updated: Dec 01 '22