@techrah/text-shortcuts
v1.0.4
Published
Insert text via shortcut keys in Jupyter Lab.
Downloads
149
Maintainers
Readme
text-shortcuts
A jupyterlab extension to insert text via keyboard shortcuts.
Pre-requisites
- JupyterLab 2.x, 3.x
- node 12+
Installation
jupyter labextension install @techrah/text-shortcuts
or add it through your Jupyter Lab Extensions tab.
Then, add some user shortcuts:
In Jupyter Lab, select Settings / Advanced Settings Editor from the menu.
Select the Keyboard Shortcuts tab.
In the User Preferences section, add your shortcuts configuration and click the "save" icon.
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.
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.
Accel
: Command (macOS) / Ctrl (Windows)Alt
: Option (macOS) / Alt (Windows)Shift
: ShiftCtrl
: Control
{
...
"args": {
"kernel": "ir",
"text": "|>",
"autoPad": true
}
...
}
kernel
(optional): If you specify akernel
, the shortcut will only work in notebooks that are running the specified kernel. Examples of kernel names areir
andpython3
. For a list of installed kernels, usejupyter kernelspec list
.text
: This is the actual text that you want inserted.autoPad
: (true
|false
). Iftrue
, will add spacing either before, after, or both before and after so that there is a single space on each side of the text.
{
...
"selector": "body"
...
}
CSS selector. Always use "body"
for this extension.
Development
Pre-requisites
- node 5+
- Python 3.6+
It is strongly recommended that you set up a virtual Python environment. These instructions will assume that Anaconda is already installed.
Create a new virtual environment and activate it.
conda create --name text-shortcuts conda activate text-shortcuts
Install jupyterlab
conda install jupyterlab
Clone this project and in the root of the project folder, install dependencies with the JupyterLab Package Manager
jlpm
Install the extension
jupyter labextension install . --no-build
Start up jupyter lab in watch mode. Don't forget to activate your virtual environment. If you want to use a different browser for development, specify that with the
--browser
switch. If you want to use a custom port, specify that with the--port
switch.conda activate text-shortcuts jupyter lab --watch --browser="chrome" --port=8889
In another terminal, run the TypeScript compiler in watch mode.
conda activate text-shortcuts jlpm tsc -w
For more information on developing JupyterLab extensions, here are some helpful resources:
- Extension Developer Guide
- Common Extension Points: Keyboard Shortcuts
- JupyterLab Extensions by Examples
- CodeMirror: Document management methods
- Interface INotebookTracker
Pull requests are welcome!