0

I'm developing my Java project with VS Code when I find some powerful snippets:

suffix code snippets

After I type a variable name and type .sysout, .cast and so on, the snippet suggestion pop out. When inserting, it leads to:

res.sysout => System.out.println(res);

res.cast => (()(res))

...

I'm curious about how to realize this feature in my VS Code. By the time, I didn't find anything useful at redhat-developer/vscode-java.

Then I want to transplant the snippet to support JS/TS, and other languages.

I detailedly read VS Code's doc about snippets, find something that might be useful:

The following variables can be used:

  • TM_SELECTED_TEXT The currently selected text or the empty string
  • TM_CURRENT_LINE The contents of the current line
  • ...

However, when I try to create the snippet, I don't know how to replace the variable name. In other words, I can get the variable name by TM_CURRENT_LINE, insert a snippet, but the previous variable name remains. For instance,

res.log => resconsole.log(res);

3
  • look at Hyper Snippets extension, where you can add code to the snippet and capture the variable as part of the snippet prefix Commented Apr 22, 2023 at 18:05
  • Correction HyperSnips Commented Apr 22, 2023 at 18:24
  • @rioV8 Yeah I've tried this extension. Could you please show some examples? I'm a little confused when using it. Thanks! Commented Apr 23, 2023 at 0:45

1 Answer 1

2

This feature is called post-fix completion: https://code.visualstudio.com/docs/java/java-editing#_postfix-snippet-shortcuts

For TS/JS, there are some extensions support that, for example:

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your recommendation, this extension is what I need :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.