I want to set that if I write a colon, I am automatically added a space after it. I used to use IntelliJ IDEA, which did this automatically when working with JSON. Can this be set in VSC as well?
Asked
Active
Viewed 557 times
0
-
what if you add a keybinding to `:` to `type` `: ` (colon space) – rioV8 Oct 12 '20 at 09:50
-
I edited file keybindings.json like: { "key": ":", "command": "type", "args": { "text": ": " } } but, not working. – HrkBJP Oct 12 '20 at 11:10
1 Answers
0
The extension HyperSnips is one way to do it.
In your json.hsnips file (so it is limited to json
files):
snippet `:` "expand to : " A
``rv = ': '``
endsnippet
Now whenever you type a :
it will be expanded to :
in a json
file.
See https://stackoverflow.com/a/62562886/836330 for more info.
Just using :
as a key to a prefix in a keybinding won't work as you must have a modifier key - like alt, ctrl, etc. See https://code.visualstudio.com/docs/getstarted/keybindings#_accepted-keys.
You could do something like:
{
"key": "alt+;", // I chose ; because it is on the same key for me as :
"command": "type",
"args": { "text": ": " },
"when": "editorTextFocus && editorLangId == json"
},
and that would work.

Mark
- 143,421
- 24
- 428
- 436