VS Code : create custom snippet/shortcut
Asked Answered
A

1

5

I would like to have the following feature on VSCode and I don't know if it is possible. For example, if I have this line :

I would like to emphasize this.

I would just select this, clic on a shortcut like ctrl+i and then this appears :

I would like to emphasize {i}this{/i}.

I use a lot of {i} and {/i} tags in my project so this would help me save an incredible amount of time !

I know VSCode already does something similar when you select a word and clic on "

Albertalberta answered 16/3, 2020 at 0:35 Comment(2)
See #60594420 for example, that answer wraps with a $. If you need help modifying it to wrap with your tags let me know.Underwater
Thank you @Underwater ! Works fine :) My question is in fact a duplicate but i couldn't find it as i didn't use the same wordsAlbertalberta
O
6

Find your keybindings.json file and insert the following snippet:

{
  "key": "ctrl+i",
  "command": "editor.action.insertSnippet",
  "args": {
    "snippet": "{i}$TM_SELECTED_TEXT{/i}"
  },
  "when": "editorTextFocus && editorHasSelection"
}

Key bindings can be found by pressing Ctrl+Shift+P > type "Keyboard shortcuts", full name being: Open Keyboard Shortcuts (JSON).

Ober answered 16/3, 2020 at 1:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.