AUTHOR
Julien Delange, Founder and CEO
Julien is the CEO of Codiga. Before starting Codiga, Julien was a software engineer at Twitter and Amazon Web Services.
Julien has a PhD in computer science from Universite Pierre et Marie Curie in Paris, France.
We often reuse the same blocks of code in several parts of the projects we are working on. Jetbrains IDEs have live templates, but there is no easy way to share them with other team members or share them across IDEs.
In this article, we present the Codiga Coding Assistant plugin that lets you create, share, search and imports code snippets within your IDE. Code Snippets you write with Codiga are reusable across IDEs and work seamlessly on all JetBrains IDEs or VS Code.
Install the Codiga PyCharm Plugin
First, install the Codiga plugin extension in PyCharm. Go to the preferences of PyCharm first and go to the PlugIns section. Look for the Codiga
plugin in the marketplace and click install.
The hardest part is almost done! Next, let's set up your API token set up!
Setup your Codiga API token
First, head to Codiga and create your API token. This token will link your Codiga account with PyCharm.
Once you get the API token, enter it in PyCharm. Go to the preferences. Under the Tools
section, find the Codiga
sub-section and enter your API token.
IMPORTANT: do not forget to click on Apply
before testing the API connection.
Search for Code Snippets in Pycharm using comments
In PyCharm, starts a comment and type your code snippet search in the comment. For example, enter the following request
# read csv file
The Codiga plugin suggests different code snippets based on your suggestions. You can browse the suggestions using ALT + ]
(next snippet) or ALT + [
(previous snippet). Use TAB
to insert a snippet and ESC
to remove suggestions.
IMPORTANT: the Codiga engine uses all the words in the comments to find snippets based on their keywords. If you create a code snippet on Codiga and want to make them searchable, make sure you add keywords to your code snippets.
Search for Code Snippets in Pycharm using embedded search
Sometimes, you prefer a search interface to browse all code snippets. Open the code snippets panel in PyCharm. The panel finds the language in the editor and suggests code snippets based on the packages being used in your environment.
Enter your search request. You can then go on the button to preview the snippet and if the snippet is what you need, click to insert it into your code.
IMPORTANT: the Codiga engine uses all the words in the comments to find snippets based on their keywords. If you create a code snippet on Codiga and want to make them searchable, make sure you add keywords to your code snippets.
Use a Code Snippet in PyCharm using shortcuts
Some code snippets have a shortcut (you can see the shortcut in the code snippet panel). Shortcuts are associated when you create the snippets. They are a great way to associate a code snippet with a short keyword.
Start typing a .
in your editor, followed by the shortcut you want to use. Codiga will then suggests shortcuts as you type. Select the shortcut in the suggestions to insert it in the editor.
Create your Code Snippets in PyCharm
You can also create code snippets from PyCharm. Select the code you want to share in PyCharm, make a right click and select Create Codiga Snippet
. The plugin opens your browser to create the snippet.
After creating a snippet, you can associate the following elements:
- keywords: keywords are used to index the snippet and make them searchable in the snippet search, either in the panel or in the comments.
- shortcut: shortcuts make snippets easy to find. Typing a
.
followed by the keyword will suggest the snippet directly in your editor.
Share your Python Code Snippets on the Codiga Hub
When creating a code snippet on Codiga, the snippet is either public or private. Public snippets are shared on the Codiga Hub, a central repository for code snippets.
If you create code snippets for Python, your snippets will be available and indexed on the Codiga Hub. As you create more snippets, your Codiga karma will increase, unlocking badges and rewards.
Supporting other JetBrains products
The Codiga extension is also available for:
Wrapping Up
Creating code snippets in PyCharm has never been so easy with the Codiga extension. Code Snippets are shared across the Codiga community on the Codiga Hub and reusable across platforms (such as other JetBrains IDEs and VS Code).