Is it possible to use a capture group from the context of a keymap command in the argument of the keymap command?
When I am typing a single-line comment I would like to be able to press the return
key and have all of the characters (tabs, spaces, comment characters) automatically inserted before the insertion point on the new line.
Current behavior on return
(pipe used to indicate location of insertion point):
# This is a comment
|
Desired behavior:
# This is a comment
# |
Here is what I think this keymap could possibly look like (for now I have simply replaced \1
on line 3 with #
but this ignores indentation which the capture group would include, as well as allowing for other comment characters:)
{ "keys": ["enter"],
"command": "insert_snippet",
"args": {"contents": "\n\1"}, // \1 == first capture group.
"context":
[
{ "key": "preceding_text",
"operator": "regex_match",
"operand": "^([ \t]*(#|//)[ \t]*).*$",
"match_all": true },
]
},
Thanks!
Lowell