How do I add a comma after typing the “comma” inside the parenthesis?
Would anyone mind giving the key bindings for this?
How do I add a comma after typing the “comma” inside the parenthesis?
Would anyone mind giving the key bindings for this?
I’m not sure what you mean by “add a comma after typing the comma inside parenthesis”; can you provide an example of what you would like to see happening?
Hi, like assume we got a parenthesis here ( 'some text' )
.
After I type the comma, it will become ( 'some text',another text )
. but my goal is to become ( 'some text', 'another text' )
.
Note there is a space after the comma, I wanna the space automatically be inserted after typing the comma inside the parenthesis.
A keymap something like this will do that:
{ "keys": [","], "command": "insert_snippet",
"args": {"contents": ", $0"},
"context": [
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\(" },
{ "key": "following_text", "operator": "regex_contains", "operand": "\\)" },
],
},
Or if you will, at any point when you type ,
and the text before the cursor contains an open parenthesis and the text following it contains a close parenthesis, the comma will be inserted with a trailing space.
This could well trigger in more situations than you actually want to have happen, in which case the regexes may need to be made more robust (this is just a simple example) or contain more cases (e.g. so it only happens in source files and not text files or similar).