Giter Club home page Giter Club logo

jupyter-vim-binding's Introduction

jupyter-vim-binding

This extension enables VIM keybindings in Jupyter Notebook (4.0+), formerly known as IPython Notebook.

Screencast

Since the development of ivanov/ipython-vimception seems to have stalled, I decided to create a new one.

Installation

There are two ways to install the extension: 1. Directly as a notebook extension, or 2. By extending [IPython-notebook-extensions] (https://github.com/ipython-contrib/IPython-notebook-extensions)

Direct

Get the file

Recommended Clone the repository in Jupyter's data directory by running the following from a shell (e.g., bash)

> cd $(jupyter --data-dir)/nbextensions
> git clone https://github.com/lambdalisue/jupyter-vim-binding.git vim_binding

Or, if you want to use Python interface for Notebook Extensions, run the following from a Python shell or a Notebook

from notebook.nbextensions import install_nbextension
from jupyter_core.paths import jupyter_data_dir
install_nbextension('https://rawgithub.com/lambdalisue/jupyter-vim-binding/master/vim_binding.js',
                     nbextensions_dir=jupyter_data_dir()+'/nbextensions/vim_binding')

Or, from a shell

jupyter nbextension install https://rawgithub.com/lambdalisue/jupyter-vim-binding/master/vim_binding.js --nbextensions=$(jupyter --data-dir)/nbextensions/vim_binding

On Linux machines, either command should create a new file under ~/.local/share/jupyter/nbextensions/vim_binding/vim_binding.js. On Mac, this path should be ~/Library/Jupyter/nbextensions/vim_binding/vim_binding.js.

Activate temporarily

To activate the extension temporarily in a notebook session, run the following snippet in a code cell:

%%javascript
Jupyter.utils.load_extensions('vim_binding/vim_binding')

Activate permanently

To activate the extension permanently from a notebook, run the following in a code cell:

%%javascript
Jupyter.notebook.config.update({
  'load_extensions': { 'vim_binding': true },
});

Or, from a shell

jupyter nbextension enable vim_binding/vim_binding

Extending IPython-notebook-extensions

IPython-notebook-extensions contains a collection of extensions that add functionality to the Jupyter notebook. These extensions are mostly written in Javascript and will be loaded locally in your Browser.

The project simplifies the task of maintaining multiple extensions as, all extensions that are maintained and active have a markdown readme file for documentation and a yaml file to allow them being configured using the 'nbextensions' server extension.

Install IPython-notebook-extensions

Follow the instructions at https://github.com/ipython-contrib/IPython-notebook-extensions#installation. In a nutshell, clone the repository and run python setup.py install to install as local user.

Add vim_binding to IPython-notebook-extensions

Once you have installed IPython-notebook-extensions, run the following from a shell (e.g., bash):

> cd $(jupyter --data-dir)/nbextensions/usability
> git clone https://github.com/lambdalisue/jupyter-vim-binding.git vim_binding
> chmod -R go-w vim_binding

Activate the extension

Launch a Jupyter notebook session. Then, in a browser go to <root>/nbextensions/; for example, if the notebook is hosted under localhost:8888, go to localhost:8888/nbextensions/. Activate VIM binding from the list of extensions. Check documentation for more details.

Customize

To customize your Vim in Jupyter. Create a custom.js (usually at ~/.jupyter/custom/custom.js) and use CodeMirror's Vim API to configure like below:

require(['codemirror/keymap/vim'], function() {
  // Map jj to <Esc>
  CodeMirror.Vim.map("jj", "<Esc>", "insert");
  // Use gj/gk instead of j/k
  CodeMirror.Vim.map("j", "gj", "normal");
  CodeMirror.Vim.map("k", "gk", "normal");
});

License

The MIT License (MIT)

Copyright (c) 2015 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.

jupyter-vim-binding's People

Contributors

benvarkey avatar lambdalisue avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.