DEV Community

Lumin
Lumin

Posted on

2

Create VSCode User Snippet

I have enough! My VSCode always autocomplete command that I don't need when I'm about to export CommonJS module (or module.exports).

And I'm too lazy to manually type module.exports to export module in CommonJS.

To fix this, just add user snippet!

  1. Open command pallete (cmd + Shift + p)
  2. Type "user snippet" ... it should suggest "Snippets: Configure User Snippets" then hit Enter!
  3. The pallete should display a list of snippet, then choose "New Global Snippet file..." VSCode will open a new file
  4. Add this code
{
  "CommonJS export": {
    "scope": "javascript,typescript",
    "prefix": "mdep",
    "body": [
      "module.exports = {$1}"
    ],
    "description": "Export module as CommonJS"
  }
}
Enter fullscreen mode Exit fullscreen mode

What does it mean?

  • "CommonJS export" -- the name of this snippet
  • "scope": "javascript,typescript" -- this snippet will be use on JS and TS
  • "prefix": "mdep" -- I will just type mdep and got my module.exports
  • "body" -- this is the template it will generate my expected code

That's it!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay