Timathon
Timathon

Reputation: 298

Control the tab stop order for code snippet of VS Code

For example, with following code, when I type "im" and tab, I will get "import { } from ''", and the initial focus will be at $2 postion, not $1 postion. How can I have the initial focus at $1? Thanks.

{
    "import": {
        "prefix": "im",
        "body": [
            "import { $2 } from '$1'"
        ],
        "description": "import element from a module"
    }   
}

Upvotes: 2

Views: 2115

Answers (1)

Steffen
Steffen

Reputation: 3516

Not sure why it is not following the tab stop order, maybe a bug? A workaround could be to explicitly set $0 as end of your tab stop

"import": {
    "prefix": "im",
    "body": [
        "import { $0 } from '$1'"
    ],
    "description": "import element from a module"
}  

vscode Docs:

The snippet syntax follows the TextMate snippet syntax with the exception of 'regular expression replacements', 'interpolated shell code' and 'transformations', which are not supported.

TextMate snippet syntax Manual:

The caret will start at $1, then when pressing tab it will move to $2 and $3 on next tab etc. until there are no more tab stops. If you do not explicitly set $0, the caret will be at the end of the snippet.

Upvotes: 2

Related Questions