Lädt...

🔧 Code faster with custom VScode snippets


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Code snippets are templates that make it easier to enter repeating code patterns and who better than yourself knows what code you copy again and again. The best way to tackle this problem is with tailored-to-you snippets and I will show how to create them in less than 2 minutes.

Transform your code into snippets

First of all, open the snippets settings (File > Preferences / Code > Preferences on macOS, and then select the language for which the snippets should appear, or Global Snippets file for it to be available for every language).

Then get the code you want to turn into a snippet and head over to this website https://snippet-generator.app

You will get the body of the snippet, which is the text interpreted by VScode to generate your code.

You also have to fill in the rest of the snippet:

  • name a short name that will be displayed when the snippet is suggested

  • prefix defines the trigger to call the snippet

  • scope is the list of languages for which the snippet applies (ex: javascript, typescript, typescriptreact)

You should have something that looks like this

Placeholders and advanced syntax

You can further improve your snippet with placeholders, tabstops and variables. You can find the documentation here: snippet syntax doc

You can set cursor locations with $0, $1... if you write multiple times the same number you will edit the same text at each location.

Placeholders are default values that are linked to those cursor locations like this ${1:foo}

You also have default variables for example if you want the name of the current file you write TM_FILENAME_BASE . The best of it is that you can combine with placeholders.

Here is a snippet where you will have the file name as the name of the component and the default export but with cursor locations on them if you want to quickly edit it. (you will find the gist of all my snippet at the end)

One special trick, if you want to get the name of the folder, you have to use the directory path variable and transform it like this: ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}

result snippet vscode

You can find some examples of my snippets here

😄 Thanks for reading! If you found this article useful, consider following me on Twitter, I share tips on development, design and share my journey to create my own startup studio

...

🔧 Code faster with custom VScode snippets


📈 46.83 Punkte
🔧 Programmierung

🍏 Project Snippets 1.5 - Simple snippets manager with focus on projects.


📈 31.41 Punkte
🍏 iOS / Mac OS

🔧 How to Create Custom React TypeScript (.tsx) Code Snippets in Visual Studio Code


📈 28.99 Punkte
🔧 Programmierung

🔧 Custom Code Snippets in VS Code


📈 28.99 Punkte
🔧 Programmierung

🔧 Snippets para TypeScript no VSCode


📈 28.17 Punkte
🔧 Programmierung

🔧 The Best Vscode Snippets for React Typescript + Nextjs + Redux Toolkit


📈 28.17 Punkte
🔧 Programmierung

🔧 Theming using CSS Variables? Turn Them into VS Code Snippets for Faster, Error-Free Coding


📈 27.25 Punkte
🔧 Programmierung

🔧 9 Clever Tailwind Code Snippets for Faster Development


📈 27.25 Punkte
🔧 Programmierung

🎥 Write your widget code faster with these Flutter snippets


📈 27.25 Punkte
🎥 Video | Youtube

🔧 How to create custom VS Code snippets ⌨️


📈 25.91 Punkte
🔧 Programmierung

🔧 Boost Your Productivity: How to Create and Use Custom Snippets in VS Code


📈 25.91 Punkte
🔧 Programmierung

🔧 Setup Laragon's Cmder in VSCode (VSCode Extension)


📈 24.94 Punkte
🔧 Programmierung

🔧 Debug Diary: Vscode Extension Development Host Can't Fully Simulate Actual Vscode


📈 24.94 Punkte
🔧 Programmierung

🔧 Power Pages: custom Content Snippets with a HACK part 1


📈 22.82 Punkte
🔧 Programmierung

🔧 Boost Your Code Review Game with Custom VSCode Shortcuts ⌨️


📈 22.67 Punkte
🔧 Programmierung

🎥 Quickly add boilerplate code snippets with VS Code #Shorts


📈 21.88 Punkte
🎥 Video | Youtube

🔧 Share private code using Share code snippets


📈 21.88 Punkte
🔧 Programmierung

🔧 VSCode Tip 5: Navigate Faster with Breadcrumbs


📈 20.93 Punkte
🔧 Programmierung

🔧 Faster Pandas: Make Your Code Run Faster and Consume Less Memory || Miki Tebeke


📈 20.01 Punkte
🔧 Programmierung

🔧 How to create a custom VSCode theme


📈 19.58 Punkte
🔧 Programmierung

🔧 How to make a custom theme for your vscode


📈 19.58 Punkte
🔧 Programmierung

🔧 10 React Code Snippets that Every Developer Needs


📈 18.79 Punkte
🔧 Programmierung

🔧 🚀 Introducing Snippet Hub – A Smarter Way to Manage and Share Your Code Snippets


📈 18.79 Punkte
🔧 Programmierung

🔧 10 CSS Code Snippets Every UI Developer Should Know


📈 18.79 Punkte
🔧 Programmierung

🔧 Guidelines for Structuring code snippets in technical writing for GenAI-based agents


📈 18.79 Punkte
🔧 Programmierung

🔧 16 Front-End Code Snippets Worth Checking Out


📈 18.79 Punkte
🔧 Programmierung

🕵️ Frida code snippets for Android


📈 18.79 Punkte
🕵️ Reverse Engineering

🔧 Sniptix: Code Snippets for Web Development 🚀


📈 18.79 Punkte
🔧 Programmierung

🔧 The Ultimate Guide to Top 10 Useful C# Code Snippets 💯


📈 18.79 Punkte
🔧 Programmierung

🔧 Fix 105 Common WordPress Issues Using Simple Code Snippets


📈 18.79 Punkte
🔧 Programmierung

📰 WordPress Plugin “Code Snippets” Vulnerability Risked Over 200K Websites


📈 18.79 Punkte
📰 IT Security Nachrichten

matomo