techrah / jupyterext-text-shortcuts

A Jupyter Lab extension for keyboard text shortcuts
MIT License
50 stars 11 forks source link
jupyterlab-extension keyboard-shortcuts

text-shortcuts

A jupyterlab extension to insert text via keyboard shortcuts.

release

Pre-requisites

Installation

jupyter labextension install @techrah/text-shortcuts

or add it through your Jupyter Lab Extensions tab.

Then, add some user shortcuts:

Here are two useful shortcuts for programming in R:

{
    "shortcuts": [
        {
            "command": "text-shortcuts:insert-text",
            "args": {
                "kernel": "ir",
                "text": "|>",
                "autoPad": true
            },
            "keys": ["Accel Shift M"],
            "selector": "body"
        },
        {
            "command": "text-shortcuts:insert-text",
            "args": {
                "kernel": "ir",
                "text": "<-",
                "autoPad": true
            },
            "keys": ["Alt -"],
            "selector": "body"
        }
    ]
}

NOTE: As of version 0.1.x You do NOT need to add the above shortcuts to User Preferences unless you want to override the default behaviour. These two shortcuts are now installed by default. They can be found in Keyboard Shortcuts / System Defaults.

@techrah:text-shortcuts_default-shortcuts

Anatomy of a Text Shortcut

{
    ...
    "command": "text-shortcuts:insert-text"
    ...
}

Identifies the keyboard shortcut as a text shortcut that is intercepted by this extension.

{
    ...
    "keys": [
        "Accel Shift M"
    ],
    ...
}

keys is an array of keyboard shortcuts that activate the insertion of the text snippet. Each entry can be a combination of one or more of the following modifiers, ending with a text character. For example, "Accel Shift M" represents Command-Shift-M on macOS.

{
    ...
    "args": {
        "kernel": "ir",
        "text": "|>",
        "autoPad": true
    }
    ...
}
{
    ...
    "selector": "body"
    ...
}

CSS selector. Always use "body" for this extension.

Development

Pre-requisites

It is strongly recommended that you set up a virtual Python environment. These instructions will assume that Anaconda is already installed.

For more information on developing JupyterLab extensions, here are some helpful resources:

Pull requests are welcome!