Get completion suggestion and inspect object from (IPython) Jupyter kernel inside neovim.
There are a lots of plugins out there to help with sending Python code to a REPL, but not a lot of plugins helps extracting the benefit of interactive coding back into Neovim, where your cursor will reside most of the time. This is a simple plugin that wrap-around python package 'jupyter_client' to provide ergonomic workflow that enhance your coding experience with any Jupyter kernels.
Open a floating window to inspect object under the cursor
Command :JupyterInspect
Result from LSP hover with same object:
Very basic functionality to send code to directly to kernel in normal and visual mode.
No fancy display of execution outputs, as it would complicate the plugin a lot by having async code check if execution is complete or not. Use this alongside your terminal/qt console for basic text and image display, or notebook if you need fancy widgets or latex.
python3
provider to run remote plugins (:checkhealth provider
)python3 -m pip install -U pynvim jupyter_client
from your neovim's python provider.jupyter
to nvim-cmp sources.require('jupyter-kernel.nvim').setup(opts)
to override default options.UpdateRemotePlugins
after installed.{
"jupyter-kernel.nvim",
opts = {
inspect = {
-- opts for vim.lsp.util.open_floating_preview
window = {
max_width = 84,
},
},
-- time to wait for kernel's response in seconds
timeout = 0.5,
}
cmd = {"JupyterAttach", "JupyterInspect", "JupyterExecute"},
build = ":UpdateRemotePlugins",
keys = { { "<leader>k", "<Cmd>JupyterInspect<CR>", desc = "Inspect object in kernel" } },
}
{ -- cmp configs ...
sources = cmp.config.sources({
{ name = "jupyter" }, -- Add this
-- existing sources
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "treesitter" }
{ name = "path" },
{ name = "copilot" },
})
}
Start and run jupyter kernel using your favorite method (Notebook, qtconsole
, jupyter console
in tmux/neovim/window-manager/togglerterm/floaterm.
If you have multiple kernels running or the kernel you want to connect is not the most recently created, check the magic %connect_info
and look for something like
`... if you are local, you can connect with just:
$> jupyter <app> --existing kernel-4301.json`
Edit your code and send it to kernel however you like. Then attach the current buffer to the kernel using :JupyterAttach
command.
A popup will appear and list all the available kernels to connect to, sorted by most recently created.
nvim-cmp
, given you have it setup.JupyterInspect
to inspect word under cursor.Only the following commands are provided, without any default keymaps.
JupyterAttach
: 1st argument is path to kernel's json. If no path is provided, a popup will appear to select a running kernel to attach.
JupyterDetach
: detach buffer from kernel
JupyterInspect
: inspect object under cursor. This command send the current line and cursor location to jupyter_client
, it is up to the kernel to decide which object to inspect.
JupyterExecute
: send code to execute in kernel. Support 3 options in order:
\n
Buffer variable vim.b.jupyter_attached
to check if current buffer is attached to any kernel.
vim.keymap.set("n", "<leader>k", "<CMD>JupyterInspect<CR>", {desc = "Inspect object"})
Ipython console runs a single process, without a server-client architecture. Use jupyter console
as a replacement.
Speical thanks to those plugins for inspiration and examples.
Issues and Pull Requests are welcome. See issue #1 for a TODO list and cast your votes.