1

I have this snippet:

"Wrap with React-Fragment": {
    "prefix": "rf",
    "body": [
        "<React.Fragment>${TM_SELECTED_TEXT}</React.Fragment>$1"
    ],
}

I want to have it wrap the highlighted text when I type the prefix. For example, imagine that all these divs are highlighted:

<div></div>
<div></div>
<div></div>

Currently it just replaces the text with the body of the snippet. What should I do to make it work?

Note! I am aware of the solution of pressing F1 and selecting Insert Snippet. It is too cumbersome.

1
  • See stackoverflow.com/a/48676522/836330. In v1.49 this will work as you expect. Select your div's, type your prefix, and voila. Commented Aug 29, 2020 at 4:03

1 Answer 1

1

What about assigning a custom key shortcut ? Open keybindings.json (Preferences: Open Keyboard Shortcuts File), and paste:

{
  "key": "cmd+k 1",
  "command": "editor.action.insertSnippet",
  "when": "editorTextFocus",
  "args": {
    "langId": "javascript",
    "name": "Wrap with React-Fragment"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.