Features

Code Snippet Explorer

On the left side bar of the JupyterLab, you can click the snippet icon (</>) to open/close the code snippet explorer that contains all the saved snippets as below. You can scroll/resize code snippet explorer, order the snippets with drag and drop, and manage and search the snippets.

../_images/CodeSnippetExtensionPanel.png

Creation of a New Snippet

There are several ways to create a new snippet.

  1. Highlight lines of code and right click (or use keyboard shortcut (cmd-shift-A or ctrl-shift-A)) to save the code as a snippet. Or, you can select cell(s) and right click (or use keyboard shortcut (cmd-shift-A or ctrl-shift-A)) to save content as a snippet. Then, you will see the “Save As Code Snippet” option in JupyterLab context menu as below:

    ../_images/right_click.png

    Clicking the option will open the dialog as below where you can input name, description, language, and tags of the snippet.

    ../_images/code_snippet_input_dialog.png
  2. More easily, just drag notebook cell(s) to the code snippet explorer on the left to create a new snippet. It will also open the dialog as above for your inputs.

  3. Hit the plus button next to the search bar (refer to Search of Code Snippets) to create a new snippet from scratch.

../_images/create_from_scratch.png

Use of Code Snippets

Click the three dots or right click anywhere on the snippet you want to use. It will open code snippet menu as below to insert, copy, edit, download, or delete the snippet.

../_images/CodeSnippetMenu.png

Insert

Click the insert option to insert. It will warn you if the language is different from the kernel langauge. Additionally, on hover with six dots on the left (refer to Search of Code Snippets), drag snippet into any JupyterLab workspace to insert the snippet!

Copy

Click the copy option to copy. It will create a message on the bottom right corner as below.

../_images/copy_snippet.png

Edit

Edit the saved snippets by clicking the edit option. It will open a code snippet editor as below.

../_images/code_snippet_edit.png

Download

Download snippets and share them with others by clicking the download option. It will open a box as below to input relative path to download the snippets.

../_images/download_snippets_box.png

Delete

Delete snippets by clicking delete option. It will open a warning box as below.

../_images/delete_snippet.png

Search of Code Snippets

With the filter box as below, search snippets with name, language, and code with search bar or filter them with language/filter tags!

../_images/code_snippet_filter_box.png

Furthermore, hover over snippets to see the preview of each snippet.

../_images/code_snippet_preview.png

Change Font Size of Snippet Preivew

In the JupyterLab Settings -> Advanced Settings Editor, users can set the size of code in snippet preview to see part of its content clearly.

../_images/changePreivewFontSize.gif