• This repository has been archived on 22/Aug/2023
  • Stars
    star
    2,096
  • Rank 22,033 (Top 0.5 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jupyter meets Vim. Vimmer will fall in love.

jupyter-vim-binding

Version 2.1.0 Support Jupyter 4.1 or above MIT License Doc

Do you use Vim? And you need to use Jupyter Notebook? This is a Jupyter Notebook (formerly known as IPython Notebook) extension to enable Vim like environment powered by CodeMirror's Vim. I'm sure that this plugin helps to improve your QOL.

Screencast

This extension stands for providing a Vim like environment, so it would drastically overwrite the default mappings and introduce new behaviors. For example

  • Jupyter has two modes, Command mode and Edit mode but this extension has three modes, Jupyter mode, Vim command mode, and Insert mode
  • Jupyter provides C (Shift-c) and V (Shift-v) to perform copy and paste cells, but this extension provides yy and p to perform copy and paste cells
  • Jupyter provides <C-s> (Ctrl-s) to save a checkpoint, but this extension eliminates that mapping while :w works same
  • A lot more.

Need contributors

While I changed my job, I don't use jupyter notebook, and I can't make enough time to maintain this plugin.

So if you like this plugin, please consider being a contributor.

#89

Installation

There are several ways to install the extension, see Installation for detail. The procedure below is the most simple one for quick use (A recommended way is different from this. See the link above if you are a beginner.)

# Create required directory in case (optional)
mkdir -p $(jupyter --data-dir)/nbextensions
# Clone the repository
cd $(jupyter --data-dir)/nbextensions
git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding
# Activate the extension
jupyter nbextension enable vim_binding/vim_binding

Usage

This extension provides Jupyter mode (For manipulating Jupyter) and Vim mode (For manipulating text). In Vim mode, there is Command mode and Insert mode like native Vim. Users can distinguish these modes by the background color of the cell.

Key mappings are designed for Vimmer so probably you don't need to know much about the mapping but remember the followings to survive:

  • All mappings are shown by hitting <F1>
  • Enter Vim mode; a super mode of Vim command mode and Insert mode; by 1) Double clicking a cell, 2) Hit <Enter> on a cell, or 3) Hit i on a cell
  • Leave Vim mode and re-enter Jupyter mode by :q or <S-Esc> (Shift-Escape)
  • Enter Insert mode or leave Insert mode as like Vim (i, a, etc.)

You can find detailed information about the mappings or concept in Concept page.

Completion and Tooltip

jupyter-vim-binding supports <C-n>/<C-p> completion and <C-g> tooltip in a code cell (not in markdown / raw cell). These mappings are not listed in a help panel, due to a technical limitation.

When the user hits <C-n> or <C-p>, a completion panel like below will be shown. Once the completion panel is shown, users can select a candidate by <C-n>/<C-p> and apply by <Enter> or cancel by <Esc>.

Completion

When user hit <C-g>, a tooltip panel like below will be shown. The tooltip will disappear when users perform some actions like hitting a key.

Tooltip

Note that you can repeat <C-g> to make the tooltip larger (more information).

Plug mappings

jupyter-vim-binding provides the following <Plug> mappings for CodeMirror.

  • <Plug>(vim-binding-j) : j which move to the next cell at the cell side
  • <Plug>(vim-binding-k) : k which move to the previous cell at the cell side
  • <Plug>(vim-binding-gj) : gj which move to the next cell at the cell side
  • <Plug>(vim-binding-gk) : gk which move to the previous cell at the cell side
  • <Plug>(vim-binding-+) : + which move to the next cell at the cell side
  • <Plug>(vim-binding--) : - which move to the previous cell at the cell side
  • <Plug>(vim-binding-_) : _ which move to the next cell at the cell side

While CodeMirror's Vim does not provide noremap type of mappings. You need to use these <Plug> mappings to prevent an infinite loop (See samples in Customization section).

Customization

To customize key mappings in Vim mode, you need to understand that there are two kinds of mappings in this extension:

  1. Mappings provided by Jupyter Notebook, users can customize this type of mappings with Keyboard shortcut editor provided in IPython-notebook-extensions
  2. Mappings provided by CodeMirror's Vim, users can customize this type of mappings with custom.js as described below

To customize mappings provided by CodeMirror's Vim, create a custom.js at ~/.jupyter/custom/custom.js (at least in Linux) and use CodeMirror's Vim API to manipulate like:

// Configure CodeMirror Keymap
require([
  'nbextensions/vim_binding/vim_binding',   // depends your installation
], function() {
  // Map jj to <Esc>
  CodeMirror.Vim.map("jj", "<Esc>", "insert");
  // Swap j/k and gj/gk (Note that <Plug> mappings)
  CodeMirror.Vim.map("j", "<Plug>(vim-binding-gj)", "normal");
  CodeMirror.Vim.map("k", "<Plug>(vim-binding-gk)", "normal");
  CodeMirror.Vim.map("gj", "<Plug>(vim-binding-j)", "normal");
  CodeMirror.Vim.map("gk", "<Plug>(vim-binding-k)", "normal");
});

// Configure Jupyter Keymap
require([
  'nbextensions/vim_binding/vim_binding',
  'base/js/namespace',
], function(vim_binding, ns) {
  // Add post callback
  vim_binding.on_ready_callbacks.push(function(){
    var km = ns.keyboard_manager;
    // Allow Ctrl-2 to change the cell mode into Markdown in Vim normal mode
    km.edit_shortcuts.add_shortcut('ctrl-2', 'vim-binding:change-cell-to-markdown', true);
    // Update Help
    km.edit_shortcuts.events.trigger('rebuild.QuickHelp');
  });
});

If you would like to customize the design, create a your custom.css at ~/.jupyter/custom/custom.css (at least in Linux) like:

/* Jupyter cell is in normal mode when code mirror */
.edit_mode .cell.selected .CodeMirror-focused.cm-fat-cursor {
  background-color: #F5F6EB !important;
}
/* Jupyter cell is in insert mode when code mirror */
.edit_mode .cell.selected .CodeMirror-focused:not(.cm-fat-cursor) {
  background-color: #F6EBF1 !important;
}

See Customization to find useful snippets. Don't be afraid to share your snippets at that page ;-)

Limitation

jupyter-vim-binding has the following technical limitation. If anybody knows about a confirmed workaround for these limitations, let me know.

Google Chrome

Google Chrome prohibits javascript from overriding several key mappings such as Ctrl-N, Ctrl-T, etc. Because of this policy, users have no chance to use default key mappings of jupyter-vim-binding, such as <C-n> completion.

Vivaldi

The chromium-based Vivaldi browser provides more flexibility in key mapping customizations and might be a viable alternative to Google Chrome for power users. In contrast to Google Chrome or Chromium, (almost) all keyboard shortcuts in Vivaldi can be changed or disabled, including (but not limited to) Ctrl-N, Ctrl-T, Ctrl-J, etc.

Furthermore, Vivaldi allows assigning a keyboard shortcut to temporarily disable all other browser keyboard shortcuts, making all key mappings available for other uses. Note that this temporary change applies globally to all tabs and windows of the browser instance (or "Profile") under consideration. To confine it to a subset of tabs, use a separate profile via the --user-data-dir=... option.

Clipboard

Most modern browsers prohibit javascript from accessing a system clipboard without user action, such as clicking a button. Because of this, there is no chance to enable copy and paste through yy, dd, or p while HTML5 clipboard object cannot be retrieved in a keydown event. So Users need to use browser default mappings such as Ctrl-C, Ctrl-V if they want to copy and paste through a system clipboard.

The followings are clipboard library for javascript, but all of them require click event or no paste support.

What we need is a clipboard object which can be used for copy and paste in a keydown event rather than click event. However, I don't know any workaround for this, so it is impossible to perform copy and paste in yy or p for now.

License

The MIT License (MIT)

Copyright (c) 2015-2016 Alisue, hashnote.net

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

fern.vim

🌿 General purpose asynchronous tree viewer written in Pure Vim script
Vim Script
1,139
star
2

vim-gina

👣 Asynchronously control git repositories in Neovim/Vim 8
Vim Script
690
star
3

vim-gista

An alternative gist.vim, vim plugin which manipulate gists in Vim.
Vim Script
156
star
4

gin.vim

🥃 Gin makes you drunk on Git
TypeScript
113
star
5

glyph-palette.vim

🎨 An universal palette for Nerd Fonts
Vim Script
110
star
6

nerdfont.vim

👓 Fundemental plugin to handle Nerd Fonts in Vim
Vim Script
110
star
7

vim-pyenv

Activate the versions and the virtualenvs of pyenv within a live VIM session
Vim Script
107
star
8

guise.vim

🎭 Guise is a Vim/Neovim plugin that opens a new tab page rather than invokes a new nested instance when a user tried to open a new Vim/Neovim through a job or terminal on the instance.
TypeScript
81
star
9

fern-git-status.vim

🌿 Add Git status badge integration on file:// scheme on fern.vim
Vim Script
77
star
10

fern-renderer-nerdfont.vim

🌿 fern.vim plugin which add file type icon through nerdfont.vim
Vim Script
66
star
11

battery.vim

Show battery information on statusline/tabline of Neovim/Vim
Vim Script
65
star
12

django-codemirror-widget

Django's textarea like widget for using CodeMirror on textarea
JavaScript
62
star
13

vim-manpager

Use Vim as a MANPAGER program
Vim Script
60
star
14

lista.nvim

Neovim/Vim buffer filtering plugin
Python
57
star
15

fern-hijack.vim

Make fern.vim as a default file explorer instead of Netrw
Vim Script
46
star
16

edita.vim

🖊 A pseudo EDITOR to stay in Vim/Neovim
Vim Script
44
star
17

reword.vim

🧬 Vim plugin to provide case-preserving substitutuion
Vim Script
44
star
18

kensaku.vim

🔍 Search Japanese text in Vim's buffer with Roma-ji by Migemo
TypeScript
43
star
19

vim-unified-diff

A plugin for using unified diff in vimdiff
Vim Script
42
star
20

django-inspectional-registration

Django registration app with Inspection before activation
Python
42
star
21

django-observer

Watch modification of any type of field in Django's model and call registered callback
Python
41
star
22

neovim-prompt

A python library to produce a customizable Neovim/Vim prompt.
Python
39
star
23

django-author

Automatically update author and updated_by fields on any models
Python
36
star
24

deno-unknownutil

🦕 An utility pack for handling unknown type in deno
TypeScript
36
star
25

vim-mr

🎩 Small plugin to track MRU/MRW
Vim Script
34
star
26

vim-backslash

Automatically insert a leading backslash when editing Vim scripts
Vim Script
33
star
27

dotfiles

Personal dotfiles
Vim Script
32
star
28

pastefix.vim

A workaround Neovim plugin to fix unnamed clipboard issue
Vim Script
30
star
29

butler.vim

🫖 Your butler. A ChatGPT like Vim/Neovim plugin that communicate with the OpenAI APIs
TypeScript
29
star
30

vim-fullscreen

A plugin which help users to toggle a fullscreen mode on GVim or MacVim.
Vim Script
29
star
31

vital-Whisky

vital.vim external module collection
Vim Script
28
star
32

readablefold.vim

A Vim plugin to improve foldtext for better looks
Vim Script
28
star
33

vim-protocol

Enable remote access like ':e https://git.io/vgDtJ' without netrw.vim
Vim Script
26
star
34

vim-django-support

Add DJANGO_SETTINGS_MODULE to enable pythoncomplete or whatever for django in vim
Vim Script
24
star
35

unite-grep-vcs

An unite source package for git grep and hg grep
Vim Script
24
star
36

fern-ssh

🌿 A scheme plugin for fern.vim which show file system tree of a remote machine via SSH.
Vim Script
23
star
37

vim-findent

Find and apply a reasonable indent rule of the current buffer.
Vim Script
22
star
38

django-mfw

Django framework for developing mobile site.
Python
22
star
39

fern-renderer-devicons.vim

🌿 fern.vim plugin which add file type icon through vim-devicons
Vim Script
21
star
40

deno-async

🦕 Asynchronous primitive modules for Deno.
TypeScript
19
star
41

rs-metrics-process

⏱ Cross-platform Prometheus style process metrics collector of metrics crate
Rust
19
star
42

django-googlemap-widget

Use Googlemap on your Django app
Python
18
star
43

deno-itertools

🦕 A TypeScript port of Python's itertools and more-itertools for Deno
TypeScript
18
star
44

shareboard.vim

A HTML viewer built for vim. Useful to see output of Pandoc or Markdown
Vim Script
17
star
45

vim-quickrun-neovim-job

Vim Script
17
star
46

fern-bookmark.vim

🌿 fern.vim plugin which add bookmark scheme
Vim Script
17
star
47

session.vim

Yet another simple session management plugin for Vim/Neovim
Vim Script
16
star
48

vim-pager

Use VIM as a PAGER program
Vim Script
16
star
49

file-protocol.vim

Vim plugin to support file:// protocol with line/column support
Vim Script
16
star
50

deno-unnullish

🦕 An opposite function of nullish coalescing operator
TypeScript
15
star
51

vim-amake

An example Vim plugin for asynchronous script runner
Vim Script
15
star
52

askpass.vim

🎙 Askpass (askpass.vim) is a plugin that open a prompt on Vim/Neovim when some program (e.g. SSH) ask user input (e.g RSA key passphrase) through a job on Vim/Neovim.
TypeScript
15
star
53

fin.vim

🐟 Filter the buffer content in-place without modification
Vim Script
14
star
54

wifi.vim

Show wifi information on statusline/tabline of Neovim/Vim
Vim Script
14
star
55

django-thumbnailfield

Enhanced ImageField of Django which support automatically generating thumbnail files
Python
13
star
56

deno-workerio

🦕 Deno module to translate Worker's system of messages into Reader and Writer
TypeScript
13
star
57

fern-mapping-git.vim

Add Git related mappings on file:// scheme of fern.vim
Vim Script
12
star
58

Shareboard

Python
11
star
59

nodeunit.vim

Vim compiler for nodeunit.js
Vim Script
11
star
60

rook

A personal castle repository of homeshick
11
star
61

nose.vim

A simple compiler for using nosetests on VIM
Vim Script
11
star
62

vim-cython-syntax

Vim Script
10
star
63

vim-rplugin

Allow to support Vim 8 in a python/python3 of a remote plugin in Neovim
Python
9
star
64

docker-neovim-ci

Alpine image for Neovim in CI
Makefile
9
star
65

mr-quickfix.vim

Vim Script
9
star
66

deno-sandbox

🦕 Create a temporary sandbox directory which is removed when the instance is disposed
TypeScript
9
star
67

deno-ansi-escape-code

🦕 Utilities to trim and parse ANSI escape code
TypeScript
9
star
68

pinkyless.vim

Rest your pinkies.
Vim Script
9
star
69

vim-python-virtualenv

Activate python virtualenv within Vim
Vim Script
9
star
70

vital-ArgumentParser

A high functional argument parser in Vim
Vim Script
9
star
71

emojiprefix

🎨 Emoji prefix guide for git commit messages
8
star
72

vim-improve-diff

Improve diff in Vim
Vim Script
8
star
73

deno-disposable

🦕 Ensure a disposable resource is disposed in Deno
TypeScript
8
star
74

lambdalisue-avatar

All avatars in this repository are my personal avatars. You MUST NOT use these without permission.
8
star
75

django-universaltag

Django's universaltag library
Python
8
star
76

qfloc.vim

Vim Script
8
star
77

deno-msgpack-rpc

🦕 Deno module to support msgpack-rpc
TypeScript
8
star
78

seethrough.vim

Make Vim transparent
Vim Script
7
star
79

vim-diffa

Improve diff feature of Vim
Vim Script
7
star
80

vim-operator-breakline

A vim operator to break lines even on words
Vim Script
7
star
81

e4u

Bundle Library of emoji4unicode at Google
Python
7
star
82

fern-mapping-project-top.vim

Vim Script
7
star
83

Jencil

JavaScript Crossbrowser Markup and WYSIWYG editor written in CoffeeScript
JavaScript
7
star
84

django-roughpages

A template based the django's flatpages like app
Python
7
star
85

django-object-permission

[Obsolute] Use django-permission insted. This library is no longer supported.
Python
7
star
86

grea.vim

Asynchronous grep which works like builtin external grep in Vim
Vim Script
6
star
87

collon.zsh

Lightweight ZSH theme (ASCII only) via promptinit
Shell
6
star
88

deno-unreachable

🦕. A type-check utility function to indicating that the code is unreachable
TypeScript
6
star
89

rs-co2-mini-monitor

🦀 An CUI application to log output of CO2Mini Indoor AirQuality Monitor
Rust
6
star
90

fern-mapping-mark-children.vim

fern.vim mapping plugin to provide mappings to mark child nodes of the cursor node
Vim Script
6
star
91

django-spaminspector

Django's generic spam inspection library via Akismet
Python
6
star
92

unite-linephrase

A unite source for set phrases
Vim Script
6
star
93

vim-gista-unite

A harmonic plugin of vim-gista for unite.vim
Vim Script
6
star
94

trea.vim

POC project for next fila.vim
Vim Script
6
star
95

Minilog

Djangoでブログを作るチュートリアル的何か
Python
6
star
96

gittag-changelog

Create CHANGELOG from tags in git repository
Python
5
star
97

kensaku-search.vim

Vim Script
5
star
98

femto

A simple JavaScript Text Editor
CoffeeScript
5
star
99

pymol-sketch

Python
5
star
100

fern-mapping-quickfix.vim

Fern plugin to send nodes to quickfix/location list
Vim Script
5
star