0

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?

HrkBJP
  • 3
  • 1

1 Answers1

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