Skip to content

Commit 9a3262d

Browse files
authored
first last cell shortcuts (#24)
* first last cell shortcuts * meant to bump patch number
1 parent c88e8a9 commit 9a3262d

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,25 @@ Notebook cell vim bindings
1010
I want to acknowledge [Alisue](https://github.com/lambdalisue) and his excellent work creating [vim bindings](https://github.com/lambdalisue/jupyter-vim-binding) for Jupyter notebooks.
1111
I hope this extension can meet the high bar his work set.
1212

13+
## Modes
14+
15+
This extension splits Jupyter edit mode into two modes: Vim command mode and Vim insert mode.
16+
Three editing modes now exist: Jupyter command, Vim command, and Vim insert.
17+
1318
## Key Bindings
1419

15-
| Chord | Command |
20+
Shortcuts this extension introduces:
21+
22+
### Vim Ex commands
23+
24+
| Command | Action |
25+
| ------- | ------ |
26+
| :w[rite] | Save Notebook |
27+
| :q[uit] | Enter Jupyter command mode |
28+
29+
### Vim command bindings
30+
31+
| Chord | Action |
1632
| ----- | ------- |
1733
| Ctrl-O, U | Undo Cell Action |
1834
| Ctrl-O, - | Split Cell at Cursor |
@@ -25,11 +41,20 @@ I hope this extension can meet the high bar his work set.
2541
| Ctrl-O, Ctrl-O | Insert Cell Above |
2642
| Ctrl-J | Select Cell Below |
2743
| Ctrl-K | Select Cell Above |
44+
| Ctrl-O, G | Select First Cell |
45+
| Ctrl-O, Ctrl-G | Select Last Cell |
2846
| Command/Ctrl-1 | Code Cell Mode |
2947
| Command/Ctrl-2 | Markdown Cell Mode |
3048
| Command/Ctrl-3 | Raw Cell Mode |
3149
| Shift-Escape | Leave Vim Mode |
3250

51+
### Jupyter command bindings
52+
53+
| Chord | Action |
54+
| ----- | ------ |
55+
| G, G | Select First Cell |
56+
| Shift-G | Select Last Cell |
57+
3358
## Prerequisites
3459

3560
* JupyterLab

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab_vim",
3-
"version": "0.4.1",
3+
"version": "0.4.2-dev",
44
"description": "Code cell vim bindings",
55
"author": "Jacques Kvam",
66
"main": "lib/index.js",

src/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,30 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
300300
},
301301
isEnabled
302302
});
303+
commands.addCommand('select-first-cell', {
304+
label: 'Select First Cell',
305+
execute: args => {
306+
const current = getCurrent(args);
307+
308+
if (current) {
309+
current.notebook.activeCellIndex = 0;
310+
current.notebook.deselectAll();
311+
}
312+
},
313+
isEnabled
314+
});
315+
commands.addCommand('select-last-cell', {
316+
label: 'Select Last Cell',
317+
execute: args => {
318+
const current = getCurrent(args);
319+
320+
if (current) {
321+
current.notebook.activeCellIndex = current.notebook.widgets.length - 1;
322+
current.notebook.deselectAll();
323+
}
324+
},
325+
isEnabled
326+
});
303327

304328
commands.addKeyBinding({
305329
selector: '.jp-Notebook.jp-mod-editMode',
@@ -412,6 +436,26 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
412436
keys: ['Accel 3'],
413437
command: 'notebook:change-cell-to-raw'
414438
});
439+
commands.addKeyBinding({
440+
selector: '.jp-Notebook.jp-mod-editMode',
441+
keys: ['Ctrl O', 'G'],
442+
command: 'select-first-cell'
443+
});
444+
commands.addKeyBinding({
445+
selector: '.jp-Notebook.jp-mod-editMode',
446+
keys: ['Ctrl O', 'Ctrl G'],
447+
command: 'select-last-cell'
448+
});
449+
commands.addKeyBinding({
450+
selector: '.jp-Notebook.jp-mod-commandMode',
451+
keys: ['G', 'G'],
452+
command: 'select-first-cell'
453+
});
454+
commands.addKeyBinding({
455+
selector: '.jp-Notebook.jp-mod-commandMode',
456+
keys: ['Shift G'],
457+
command: 'select-last-cell'
458+
});
415459

416460
// tslint:disable:no-unused-expression
417461
new VimCell(app, tracker);

0 commit comments

Comments
 (0)