Skip to content

This program creates perfectly formatted user-defined code snippets for the use of the built-in code snippet tool in VS Code.

Notifications You must be signed in to change notification settings

chantalwuer/code_snippet_creator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Code Snippet Creator

Description

Some code blocks can be reused in various projects and it can increase the efficiency of the workflow to have them saved as snippets for easy access. One way of doing that when working in VS Code is using the build-in user snippets. When configured, it is enough to type a pre-defined prefix and a whole code block will be automatically inserted into the code.

To set up the code snippets, however, each code block must be correctly formatted and added to a .json file within VS Code. This can get quite tedious, especially with longer code blocks.

This program does the formatting for you. It takes as input the title, prefix, code and description and returns a fully formatted block that can be added to the .json file.

Getting Started

The program can be run from the CLI. Either by simply executing it with

python <file_path>

Alternatively, creating an alias in the .zshrc file can make access even simpler.

cd ~
code .zshrc

Add to the .zshrc file:

alias code-snippet="python <file_path>/snippet_converter.py"

Save the file and restart the terminal.

Now, running code-snippet in the CLI will be enough to start the program.

Creating a code snippet

To create a snippet, the program will prompt inputs.

  • Title: The title of your code snippet
  • Prefix: The text you write in VS Code to trigger the code snippet
  • Code Block: Your code block
  • Description: A description of what the snippet does

The output will then look like this:

image

Adding snippets to VS Code

To add the formatted snippet to VS Code, open Code/Preferences/Configure User Snippets and pick a programming language. A .json file will open and the formatted snippet can be pasted into the file, following the example given in the file.

About

This program creates perfectly formatted user-defined code snippets for the use of the built-in code snippet tool in VS Code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published