skip to Main Content

I want to make snippet for console.log(variable) but instead to have prefix I want to make this with "suffix". Here’s an example:

var name = "Marco";
var car = "Volvo";

name.log > TAB > console.log(name);

When I write my variable "name" after that ".log" like in example above. After that pressing TAB key on keyboard i want to get my "console.log(name);".
When I do it like this: car.log > TAB, I want to get "console.log(car);".

2

Answers


  1. Looking at the documentation for Snippets, I don’t think what you’re asking for is supported.

    The mechanism for using snippets is based on exact matches of text (the prefix field), and while the variables include things like TM_CURRENT_LINE and TM_CURRENT_WORD, and even given those, I can’t see a way to work them to do what you want.

    The closest I could get was

    "test": {
        "prefix": ".log",
        "body": "console.log(${TM_CURRENT_LINE/^(\s+.*?)?(\w+)\.log(.*)$/$2/})"
    }
    

    But I don’t know how to "consume" / remove the pre-existing text preceding the snippet prefix.

    Login or Signup to reply.
  2. what you can do is

    • type name
    • select name, useCtrl+D
    • type clog

    clog is the following snippet:

    "consolelog": {
        "prefix": "clog",
        "body": "console.log(${TM_SELECTED_TEXT})"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search