File size: 1,852 Bytes
fdaf774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Snippets
========

Code cell snippets.

This extension adds a drop-down menu to the IPython toolbar that allows easy
insertion of code snippet cells into the current notebook. The code snippets
are defined in a JSON file in `nbextensions/snippets/snippets.json` and an
example snippet is included with this extension.

![](snippets-demo.gif)

Adding new snippets
-------------------

Snippets are specified by adding a new JSON block to the list of existing snippets in `$(jupyter --data-dir)/nbextensions/snippets/snippets.json`. For example, to add a new snippet that imports numpy, matplotlib, and a print statement, the JSON file should be modified from:

```json
{
    "snippets" : [
        {
            "name" : "example",
            "code" : [
                "# This is an example snippet!",
                "# To create your own, add a new snippet block to the",
                "# snippets.json file in your jupyter data directory under nbextensions:",
                "# $(jupyter --data-dir)/nbextensions/snippets/snippets.json",
                "import this"
            ]
        }
    ]
}
```

to this:

```json
{
    "snippets" : [
        {
            "name" : "example",
            "code" : [
                "# This is an example snippet!",
                "# To create your own, add a new snippet block to the",
                "# snippets.json file in your jupyter data directory under nbextensions:",
                "# $(jupyter --data-dir)/nbextensions/snippets/snippets.json",
                "import this"
            ]
        },
        {
            "name" : "some imports",
            "code" : [
                "import numpy as np",
                "import matplotlib as mpl",
                "print('spam')"
            ]
        }
    ]
}
```
You may need to restart your notebook for the changes to take effect.