Search code examples
visual-studio-codecode-snippetsvscode-extensions

Visual Studio Code snippet that inserts the method/function name?


I am not looking for a snippet that creates a method or function, I want a snippet that inserts the name of the method/function automatically.

Precisely, I would like something like this:

console.log('${TM_METHODNAME}: ${1}')

Unfortunately, TM_METHODNAME is not part of the default set of variables.

There doesn't seem to be an extension available for that either.

Maybe a compromise would be to use TM_SELECTED_TEXT, although I don't understand how it works, as when typing the snippet prefix, the selected text is obviously erased.


Solution

  • As of v1.20 you can use CLIPBOARD as a variable, see v1.20 release notes so you could copy the method name first and have it ready to use in the snippet. I think at this point that is your only option.