Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Daniel Bellmas
Daniel Bellmas

Posted on • Edited on

     

My Custom Snippets in VScode

Hi Everyone!

This one is short but sweet 🙂

To create your own snippets you'll need to selectCode >Preferences (User Snippets underFile >Preferences on Windows), and then select the language for which the snippets should appear, or the New Global Snippets file option.

And here are my three favorite ones, and I'll explain why:

  1. For scss files where$spacer = 1rem
"Add spacer":{"prefix":"s","body":["* $$spacer"],"description":"Adds a spacer to the current line"}
Enter fullscreen modeExit fullscreen mode

I use this one a lot with the key binding I made, (to see how, you'll need to see my other post aboutkey bindings).

And here is the code for that:

//Calculatethecurrentselection{"key":"ctrl+m","command":"editor.emmet.action.evaluateMathExpression","when":"editorHasSelection"}
Enter fullscreen modeExit fullscreen mode

This shortcut will make you stay in vscode and use its inner calculator rather than touching your mouse and slowing you down...
And you know how much they don't like us touching our mice.
(I couldn't find a good meme, is that even possible?!)

  1. For the global scope: to add todo comments quickly
"TODO comment":{"prefix":"to","body":"// TODO $1","description":"Add a TODO comment"}
Enter fullscreen modeExit fullscreen mode

And the last one that I use almost all the time is theconsole.log() snippet, and again if you want to create your own keyboard shortcut that uses a snippet too 🤯 you can find ithere.

This is a special case where we use a snippet and the keyboard shortcut, which is honestly the best of both worlds.

Best of both worlds

Here is the code for it:

//Addanemptylogstatement{"key":"shift+cmd+l","command":"editor.action.insertSnippet","when":"editorTextFocus && !editorHasSelection","args":{"snippet":"console.log($1);"}}
Enter fullscreen modeExit fullscreen mode

For more information on snippets in general visit:
Snippets in Visual Studio Code

Top comments(3)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
dranoid profile image
dranoid
An inquisitive fellow
  • Education
    Covenant University
  • Joined

How did i ever not think of the TODO snippet😑😂. This was a nice read!

CollapseExpand
 
danielbellmas profile image
Daniel Bellmas
Full-Stack Developer
  • Joined

Changed my life 😂.
Thank you!!

CollapseExpand
 
oryam profile image
Oryam
Web developer
  • Location
    Israel
  • Education
    bootcamp | online courses
  • Work
    web developer
  • Joined

+1 for the spacer and the evaluation 🚀

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full-Stack Developer
  • Joined

More fromDaniel Bellmas

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp