Using TM_SELECTED_TEXT in my custom snippets

后端 未结 4 1219
醉话见心
醉话见心 2021-01-04 19:06

With the November 2016 (version 1.8) release of VSCode Snippet Variables are now supported, specifically TM_SELECTED_TEXT.

This makes me happy as I have used these h

4条回答
  •  天命终不由人
    2021-01-04 19:39

    Coming in 1.49 (it is in the Insiders' Build as of this edit) your example will finally work as you expected. See merged pull request.

    Vscode will now "remember" your selected text if any, and when you type your snippet prefix, insert it into the TM_SELECTED_TEXT variable even though you seemingly over-typed that selected text.


    As of v1.20 this has become easier as a new variable $CLIPBOARD has been added, see new snippet variables. So there is no need to assign and run a shortcut - but you must copy the selection to clipboard CTRL-C.

    Your example could now be:

    "in quotes": {
        "prefix": "inq",
        "body": "'$CLIPBOARD:${1:type_here}'"
    }
    

    Note: $CLIPBOARD works. There's no need for the extra curly brackets {$CLIPBOARD}.

提交回复
热议问题