DEV Community

Cover image for Enhance Your Productivity with Code-Snippets in VSCode
Hassan Suhaib
Hassan Suhaib

Posted on

1

Enhance Your Productivity with Code-Snippets in VSCode

I've been using a lot of Python27 recently and since there's no f-strings in it, I have to write a lot of code like this for debugging:

logging.info("This variable: {}".format(variable))
Enter fullscreen mode Exit fullscreen mode

which I really hate.

Using Code Snippets has really been helpful in this regard since I can just type any letter combination that I have configured and get a boilerplate of what I want to code.

E.g. on typing plog I get:

logging.info('${1:placeholder}: {}'.format(${1:placeholder}))
Enter fullscreen mode Exit fullscreen mode

and if I start typing after pressing enter, the placeholder 1:placeholder gets replaced with whatever I typed. Since in this example there are two placeholders, pressing enter will replace them both simulataneously.

If you have set a placeholder like 2:placeholder then you can just hit tab after you're done replacing 1:placeholder so that you can edit 2:placeholder.

Here's how you can do it in VSCode.
Open VSCode and press ctrl + shift + P. Type "Snippet: Configure Code Snippets" and hit enter.

Code Snippet Option VSCode

Select a language (I'll select Python).

Language Selection in Code Snippet

Then add snippets like so. Notice that each new line is a new entry in the body array.

Code Snippets Configuration

Save the file.

Now let's say I type imndb

Typing imndb

and press enter, it gets replaced with my saved code snippet.

imndb Code Snippet

Hope this was helpful in improving your workflow. Feel free to drop a comment and share with your friends.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

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

Okay