Reputation: 48
I'm developing my Java project with VS Code when I find some powerful 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 stringTM_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);
Upvotes: 0
Views: 366
Reputation: 1275
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:
Upvotes: 2