• Stars
    star
    413
  • Rank 104,801 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

IPython/Jupyter plugin for Neovim

nvim-ipy

This is a Jupyter front-end for Neovim, partially based on ivanov/vim-ipython, but refactored for nvim's plugin architechture and improved async event handling. Jupyter 4.x or later is required. It uses python3 per default; see below for notes on using python2. It has full support for non-python kernels.

It doesn't have all features of vim-ipython, but it has better support for long-running commands that continously produce output, for instance this silly example:

from time import sleep
for i in range(10):
    sleep(0.5)
    print(i)

Connecting/starting kernel

:IPython <args> is interpreted just like the command line jupyter console <args>, for instance:

Action command
Start new python kernel :IPython
:IPython2 (for python2 kernel)
Connect to existing kernel :IPython --existing
Start kernel in different language :IPython --kernel julia-0.6

This plugin runs in the python3 host by default, but the kernel process don't need to be the same version of python as the plugin runs in. Kernelspec can be used to launch a python2 kernel, the same way as from the Jupyter console and notebook. Use :IPython --kernel python2 or the :IPython2 shortcut. You might need to execute

ipython2 kernelspec install-self --user

on beforehand for this to work. I have tested that this plugin also supports IJulia and IHaskell, but ideally it should work with any Jupyter kernel.

If you only have the python2 host installed, you could do cd rplugin; ln -s python3 python to run this plugin in the python2 host instead.

:IPython can be invoked multiple times in the same nvim session. The old kernel connection is then closed and forgotten.

New: --no-window can be passed an argument to :IPython to hide the output window.

Keybindings

When kernel is running, following bindings can be used:

Generic default Action
<Plug>(IPy-Run) <F5> Excecute current line or visual selection
<Plug>(IPy-RunCell) Excecute current cell (see below)
<Plug>(IPy-RunAll) Excecute all lines in buffer
<Plug>(IPy-RunOp) Operator: execute over a movement or text object
<Plug>(IPy-Complete) <C-F> (insert mode) Kernel code completion
<Plug>(IPy-WordObjInfo) <leader>? Inspect variable under the cursor
<Plug>(IPy-Interrupt) <F8> Send interrupt to kernel
<Plug>(IPy-Terminate) Terminate kernel

But... The default bindings suck!

Yes, they exist mainly to quickly test this plugin. Add

let g:nvim_ipy_perform_mappings = 0

To your nvimrc and map to the generic bindings. For instance:

map <silent> <c-s> <Plug>(IPy-Run)

Cells

As a convenience, the plugin includes a definition of code cells (running only for now, later I might make them text objects). The cell is defined by setting g:ipy_celldef a list of two of rexexes that should match the beginning and end of a cell respecively. If a string is supplied, it will be used for both, and in addition the beginning and the end of the buffer will implicitly work as cells. The default is equivalent to:

let g:ipy_celldef = '^##'

To enable to define cells in a filetype, b:ipy_celldef will override the global value. As an example, add this to vimrc to support R notebooks (.rmd):

au FileType rmd let b:ipy_celldef = ['^```{r}$', '^```$']

You also need to map some key to IPy-RunCell:

map <silent> <leader>c <Plug>(IPy-RunCell)

Options

NB: the option system will soon be rewritten to allow changing options while the plugin is running, but for now you can set:

Option default Action
g:ipy_set_ft 0 (false) set filetype of output buffer to kernel language
g:ipy_highlight 1 (true) add highlights for ANSI sequences in the output
g:ipy_truncate_input 0 when > 0, don't echo inputs larger than this number of lines
g:ipy_shortprompt 0 (false) use shorter prompts (TODO: let user set arbitrary format)
g:ipy_celldef '^##' definition of a code cell, see above

Note that the filetype syntax highlight could interact badly with the highlights sent from the kernel as ANSI sequences (in IPython tracebacks, for instance). Therefore both are not enabled by default. I might look into a better solution for this.

Exported vimscript functions

Most useful is IPyRun("string of code"[, silent]) which can be called to programmatically execute any code. The optional silent will avoid printing code and result to the console if nonzero. This is useful to bind common commands to a key. This will close all figures in matplotlib:

nnoremap <Leader>c :call IPyRun('close("all")',1)<cr>

IPyConnect(args...) can likewise be used to connect with vimscript generated arguments.

IPyOmniFunc can be used as &completefunc/&omnifunc for use with a completer framework. Note that unlike <Plug>(IPy-Complete) this is synchronous and waits for the kernel, so if the kernel hangs this will hang nvim! For use with async completion like Deoplete it would be better to create a dedicated source.

More Repositories

1

nvim-luadev

REPL/debug console for nvim lua plugins
Lua
264
star
2

nvim-miniyank

killring-alike plugin for neovim and vim 8 with no default mappings
Lua
230
star
3

Neovim.jl

Neovim client for Julia
Julia
41
star
4

bfredl.github.io

public docs and dotfiles
Lua
17
star
5

forklift

x86-64 JIT backend for Zig
Zig
16
star
6

nvim-incnormal

Probably the most insane multi-cursor plugin for Neovim
Vim Script
15
star
7

vim-argclinic

movements and operators for manipulating argument lists
Vim Script
10
star
8

pangoterm

C
10
star
9

nvim-zigclient

nvim-zigclient
Lua
10
star
10

nvim-matrix

Simple matrix client in nvim
Python
6
star
11

nvim-jupyter

neovim - jupyter kernels interaction (testing)
Python
6
star
12

zigui

zig all the things (libvterm, nvim ext_multigrid, and so on)
Zig
5
star
13

ibus-chords

Experiments with key chords and such stuff
Python
5
star
14

eiri

Self-contained kprobe/uprobe+eBPF tracer in zig
Zig
5
star
15

nvim-lanterna

Lua
5
star
16

nvim-miniluv

Lua
4
star
17

nvim-cxx

neovim c++ experiment (not finished)
C++
2
star
18

nvim-lspmirror

Nvim LSP PR mirror as a plugin for neovim master
Lua
2
star
19

libtickit

Mirror of http://bazaar.leonerd.org.uk/c/libtickit/
C
2
star
20

nvim-luvlsp

Old luv-based LSP client sketch. Since integrated into the mainline nvim 0.5 client
Lua
2
star
21

GI.jl

GObject-introspection for julia
Julia
1
star
22

SKRAPET

CSS
1
star
23

nvim-bufmngr

Vim Script
1
star
24

weebgpu

weebgpu
C
1
star
25

typetrainer

Python
1
star
26

advent2021

Assembly
1
star
27

tutorial

Jupyter Notebook
1
star
28

x

1
star
29

bmidi

C++
1
star
30

nvim-lspext

Lua
1
star
31

nvim-x11

Prototype of native X11 selections for neovim
C
1
star