Skip to content

glmlm/JuviterNeotbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Juviter Neotbook

demo

OOTB Jupyter Notebook experience in Neovim

👋 Preface

This plugin simply suggests best practices for the integration of each plugin. In short, it corresponds to an Extension Pack in VSCode.

The parts of this plugin that are set independently (global variables, user/auto commands, etc.) are subject to maintenance. If you require any information regarding the functions of each plugin, I kindly request that you reach out to the respective maintainer.

Goals

  • Improve Jupyter Notebook development experience on Neovim (at least for me)
  • Explore better ways to integrate each plugins

Non-Goals

  • Implement functionality as an independent plugin
    • In the event that the feature is considered to be a truly expected one, it might be worthwhile to consider creating a separate repository. In that case, the setup of it could be mentioned on this plugin.

⚡️ Requirements

  • Neovim >= 0.10.0
  • Python >= 3.10.0
    • pynvim
    • ipykernel
    • nbformat
    • jupytext
  • (Optional) LSP setup for Python (such as basedpyright)
  • (Optional) Image provider (see below)

📦 Setup

Setup Python

Install pynvim, ipykernel, and nbformat
$ pip install pynvim ipykernel nbformat
Install jupytext
$ pip install jupytext

You can also install it via mason.nvim.

Set a global variable

Add this line to your config file of Neovim:

vim.g.python3_host_prog = "/path/to/python"

(Optional) Setup an image provider

Note

This feature requires a terminal that supports the Kitty Graphics Protocol. If you skip this section, the default image viewer will be used instead.

Linux
$ sudo apt install liblua5.1-0-dev
$ sudo apt install libmagickwand-dev
macOS
$ brew install luajit
$ brew install imagemagick
Windows

Currently, native Windows cannot handle inline images. As an alternative, you can use Wezterm to display images in the terminal.

> scoop install wezterm

It may be possible in the future when image.nvim can handle sixel.

Install the plugin with lazy.nvim

{
  "glmlm/JuviterNeotbook",
  import = "juviter.plugins",
  keys = {
    {
      "<leader>rc",
      function()
        require("quarto.runner").run_cell()
      end,
      desc = "Juviter Run Cell",
    },
    {
      "<leader>ra",
      function()
        require("quarto.runner").run_above()
      end,
      desc = "Juviter Run cell and above",
    },
    {
      "<leader>rA",
      function()
        require("quarto.runner").run_all()
      end,
      desc = "Juviter Run all cells",
    },
    { "<leader>rd", ":noautocmd MoltenDelete<CR>", silent = true, desc = "Juviter Delete cell" },
    { "<leader>ri", ":noautocmd MoltenInterrupt<CR>", silent = true, desc = "Juviter Send a keyboard interrupt" },
    { "<leader>ro", ":noautocmd MoltenEnterOutput<CR>", silent = true, desc = "Juviter Open output window" },
    { "<leader>nj", "<cmd>NewNotebook<CR>", silent = true, desc = "Juviter Create a new notebook" },
    {
      mode = { "x", "o" },
      "ib",
      function()
        require("nvim-treesitter-textobjects.select").select_textobject("@code_cell.inner", "textobjects")
      end,
      desc = "Textobjects Code Cell Select In Block",
    },
    {
      mode = { "x", "o" },
      "ab",
      function()
        require("nvim-treesitter-textobjects.select").select_textobject("@code_cell.outer", "textobjects")
      end,
      desc = "Textobjects Code Cell Select Around Block",
    },
    {
      "<leader>sbl",
      function()
        require("nvim-treesitter-textobjects.swap").swap_next("@code_cell.outer")
      end,
      desc = "Textobjects Code Cell Swap Next",
    },
    {
      "<leader>sbh",
      function()
        require("nvim-treesitter-textobjects.swap").swap_previous("@code_cell.outer")
      end,
      desc = "Textobjects Code Cell Swap Previous",
    },
    {
      mode = { "n", "x", "o" },
      "]b",
      function()
        require("nvim-treesitter-textobjects.move").goto_next_start("@code_cell.inner", "textobjects")
      end,
      desc = "Textobjects Code Cell Move To Next Code Block",
    },
    {
      mode = { "n", "x", "o" },
      "[b",
      function()
        require("nvim-treesitter-textobjects.move").goto_next_start("@code_cell.inner", "textobjects")
      end,
      desc = "Textobjects Code Cell Move To Previous Code Block",
    },
  },
}

First-time only operation

  1. Open Neovim
  2. :lua require "molten.health"
  3. :UpdateRemotePlugins
  4. Restart Neovim

❓ FAQ

I got an error during setup.

There are two main reasons why this happens:

Case #1: Python is not set up (or the path is incorrect/missing)

See above

Case #2: rplugin.vim is disabled

Certain Neovim distributions may disable loading of default plugins. molten-nvim requires runtime/plugin/rplugin.vim, so if it is missing, the following error is raised when the :UpdateRemotePlugins command is entered.

E492: Not an editor command: UpdateRemotePlugins

As for NvChad, you can enable it by deleting this line.

An error occurs when saving outputs.

:MoltenExportOutput depends on nvim-treesitter. To enable it, enter the following command:

:TSInstall python
Past outputs are not displayed.

If a valid kernel is not running, the outputs will not be imported. To select the kernel, enter the MoltenImportOutput command or just reopen the buffer.

Images are not displayed.

If the image provider is not set up, images from previous runs will not be loaded.

Also, even if you have set up image.nvim, The image disappears when the buffer is switched. If you want to display it again, enter the :noautocmd MoltenEnterOutput command on the code block or just reopen the buffer.

Acknowledgements

The documentation of molten-nvim proved to be a valuable resource in the creation of this plugin. I would like to take this opportunity to express my gratitude.

About

OOTB Jupyter Notebook experience in Neovim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published