Skip to content

Preserve Current Selection when using snippet with TM_SELECTED_TEXT variable #62907

@markusdd

Description

@markusdd

Currently snippets with prefixes set become rather useless when they contain the selected text variable.

I have a snippet like this:

  "lint_checking": {
    "prefix": "lin",
    "body": [
      "//lint_checking ${1:RULE_ID} off",
      "$TM_SELECTED_TEXT",
      "//lint_checking ${1:RULE_ID} on"
    ],
    "description": "lint pragmas"
  }

What I want is being able to select text, start typing lin (which will of course remove the selection) and then IntelliSense will recommend lin as a completion. When I press enter I want the selection to reappear, surrounded by my snippet.

This behavior is actually standard in other editors and I was kind of surprised to find no useful way to use snippets with a completion prefix when the selction variable is being used.

If this is unwanted by some users this should be made configurable as an option, but as a hardware developer I find myself in the situation quite often where this would be useful, as such 'surrounding pragmas' are pretty common.

Another variant would be to make snippets able to be promoted to commands for the Ctrl+Shift+P command palette, so we don't have to go into the insert snippet sub palette. I do not want to assign dedicated Key Bindings, as it just becomes to much. The prefix 'is the keybinding'.

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityinsiders-releasedPatch has been released in VS Code Insiderssnippetsverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions