9

I want to access Jupyter notebook from inside vim.

I have compile vim with Python support, and try this plugin http://github.com/ivanov/vim-ipython. The documentation suggest me to run :IPython command. This seems to not working at all. Some thread on the internet give me a gist that probably the project has been abandoned and people use vim binding in jupyter notebook instead of accessing notebook from inside vim. https://github.com/lambdalisue/jupyter-vim-binding.

The problem is, I also like to have some plugins as vim-jedi etc. Using the vim binding doesn't make any plugin I installed in vim accessible from inside Jupyter notebook.

Since I have try to search in google with no satisfying result, I really want to ensure, whether there is a way to access Jupyter notebook (editing Ipynb in the correct way by using vim) or not.

Thank you.

Tumbler41
  • 7,746
  • 1
  • 21
  • 48
goFrendiAsgard
  • 333
  • 1
  • 3
  • 8
  • Second line under the title, on the project's page: "IPython versions 0.11.x, 0.12.x, 0.13.x, 1.x, 2.x and 3.x". – Sato Katsura Sep 07 '16 at 18:36
  • 1
    Did you have a look at: https://github.com/goerz/jupytext.vim – Konrad Apr 05 '22 at 09:09
  • Recently I wrote a LitREPL plugin where I tried to emulate Jupyter look-and-feel for plain Markdown and Latex documents. In particular, the plugin detects code blocks, pipes them through the background interpreter and pastes results back to the document. Other similar plugins do exist. – Grwlf Aug 23 '22 at 09:57

2 Answers2

2

This maybe not the answer to your question, but perhaps an answer to your problem with vim-ipython: you could try http://github.com/wilywampa/vim-ipython

It doesn't seem that it is too active either, but at least it works for me with Jupyter 5.0.0.

Make sure to read the help thoroughly as there are several actions to be done to make it work.

I made a small convenience script to connect easier:

import IPython
from IPython.lib import kernel
print 'Path to kernel:'
print IPython.lib.kernel.get_connection_file()

def completion_metadata(ip):
    return [dict(word=m) for m in ip.Completer.matches]

Then if you started your notebook as -> python ~/.vim/plugged/vim-ipython/monitor.py & jupyter console, (or qtconsole) you could just execute :IPython --existing path/to/kernel/printed to connect to a correct kernel. (although simple :IPython should also work with just the lastest kernel you started)

The function provides (no) additional info that is shown when using omni-completion (if you don't have it you will see errors in the notebook).

maksay
  • 58
  • 4
  • Still got problem with ctrl+s. But at least I got :IPython command working now. Thank you – goFrendiAsgard Sep 08 '16 at 09:26
  • I don't remember exactly what were the default mappings, but you could just take a look at how they are defined in ipy.vim file of the plugin and change accordingly. For example, I use:
    `au FileType python nmap <buffer> <silent> <CR> <Plug>(IPython-RunLine)`
    
    `au FileType python xmap <buffer> <silent> <CR> <Plug>(IPython-RunLines)`
    
    `au FileType python nmap <buffer> <silent> gd <Plug>(IPython-OpenPyDoc)`
    
    `au FileType python nmap <buffer> <silent> <leader>r <Plug>(IPython-RunFile)`
    
    – maksay Sep 08 '16 at 10:13
0

Jupytext.vim

jupytext.vim seems to be a step in the right direction.

You need to install a Python package called jupytext, and the vim plugin. (I used vim-plug with `Plug 'https://github.com/goerz/jupytext.vim').

I can now check the content of an ipynb file directly in vim, without starting Jupyter notebook.

I can edit the Markdown parts or the Python code, and the ipynb is updated accordingly when saving.

This is what it looks like on my computer:

neovim + juptytext -> jupyter

Eric Duminil
  • 123
  • 6