### Vanilla NixOS with lazy.nvim setup Source: https://github.com/benlubas/molten-nvim/blob/main/docs/NixOS.md Creates a custom Neovim wrapper using neovimUtils and wrapNeovimUnstable for systems without Home Manager. Includes Python packages and tree-sitter override. Requires importing this file into configuration.nix. ```nix { lib, pkgs, neovimUtils, wrapNeovimUnstable, ... }: let config = pkgs.neovimUtils.makeNeovimConfig { extraLuaPackages = p: with p; [ # ... other lua packages p.magick # for image rendering ]; extraPython3Packages = p: with p; [ pynvim jupyter-client cairosvg # for image rendering ipython nbformat # ... other python packages ]; extraPackages = p: with p; [ imageMagick # for image rendering # ... other packages ]; withNodeJs = true; withRuby = true; withPython3 = true; # https://github.com/NixOS/nixpkgs/issues/211998 customRC = "luafile ~/.config/nvim/init.lua"; }; in { nixpkgs.overlays = [ (_: super: { neovim-custom = pkgs.wrapNeovimUnstable (super.neovim-unwrapped.overrideAttrs (oldAttrs: { buildInputs = oldAttrs.buildInputs ++ [ super.tree-sitter ]; })) config; }) ]; environment.systemPackages = with pkgs; [ neovim-custom # Can't install this with the rest of the python packages b/c this needs to be in path python3Packages.jupytext # if you want to use vim-jupytext or similar # ... other system packages ]; } ``` -------------------------------- ### Lazy.nvim configuration for Molten and image.nvim Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Not-So-Quick-Start-Guide.md Sample Lazy.nvim plugin specification for installing Molten with image.nvim as a dependency. Sets vim.g.molten_image_provider and vim.g.molten_output_win_max_height as examples, not defaults. Requires running :UpdateRemotePlugins after install/update; remote plugins may be disabled by some distros. ```lua return { { "benlubas/molten-nvim", version = "^1.0.0", -- use version <2.0.0 to avoid breaking changes dependencies = { "3rd/image.nvim" }, build = ":UpdateRemotePlugins", init = function() -- these are examples, not defaults. Please see the readme vim.g.molten_image_provider = "image.nvim" vim.g.molten_output_win_max_height = 20 end, }, { -- see the image.nvim readme for more information about configuring this plugin "3rd/image.nvim", opts = { backend = "kitty", -- whatever backend you would like to use max_width = 100, max_height = 12, max_height_window_percentage = math.huge, max_width_window_percentage = math.huge, window_overlap_clear_enabled = true, -- toggles images when windows are overlapped window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" }, }, } }, ``` -------------------------------- ### Install .NET interactive tools Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Not-So-Quick-Start-Guide.md Install the .NET interactive tool and register the Jupyter kernel. These commands are required for .NET support in Molten. ```bash dotnet tool install -g Microsoft.dotnet-interactive ``` ```bash dotnet interactive jupyter install ``` -------------------------------- ### Home Manager Neovim plugin and package setup Source: https://github.com/benlubas/molten-nvim/blob/main/docs/NixOS.md Configures Neovim plugins and extra packages for molten-nvim and image-nvim. Includes Python packages like pynvim and jupyter-client. Lines marked '# for image rendering' can be removed if image support is not needed. ```nix # home.nix or wherever you configure neovim { pkgs, ... }: # ... other config programs.neovim = { # whatever other neovim configuration you have plugins = with pkgs.vimPlugins; [ # ... other plugins image-nvim # for image rendering molten-nvim ]; extraPackages = with pkgs; [ # ... other packages imagemagick # for image rendering ]; extraLuaPackages = ps: with ps; [ # ... other lua packages magick # for image rendering ]; extraPython3Packages = ps: with ps; [ # ... other python packages pynvim jupyter-client cairosvg # for image rendering pnglatex # for image rendering plotly # for image rendering pyperclip ]; }; } ``` -------------------------------- ### Install molten-nvim with lazy.nvim Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Probably-Too-Quick-Start-Guide.md Lazy.nvim plugin specification for molten-nvim. Requires pynvim and jupyter_client. Sets vim.g.molten_output_win_max_height to 12 as an example, not a default. ```lua { "benlubas/molten-nvim", version = "^1.0.0", -- use version <2.0.0 to avoid breaking changes build = ":UpdateRemotePlugins", init = function() -- this is an example, not a default. Please see the readme for more configuration options vim.g.molten_output_win_max_height = 12 end, }, ``` -------------------------------- ### Image.nvim sample configuration for Molten Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Not-So-Quick-Start-Guide.md Sample image.nvim setup table to pass to `require('image').setup`. `max_width` and `max_height` must be set to prevent terminal crashes; `max_height_window_percentage` should be `math.huge` for correct Molten output window dimensions. ```lua -- image nvim options table. Pass to `require('image').setup` { backend = "kitty", -- Kitty will provide the best experience, but you need a compatible terminal integrations = {}, -- do whatever you want with image.nvim's integrations max_width = 100, -- tweak to preference max_height = 12, -- ^ max_height_window_percentage = math.huge, -- this is necessary for a good experience max_width_window_percentage = math.huge, window_overlap_clear_enabled = true, window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" }, }, ``` -------------------------------- ### Install kernel in a project virtual environment Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Virtual-Environments.md Activates the project venv, installs ipykernel, and registers a kernel named after the project. After this, launch Neovim with the venv active and run :MoltenInit project_name. ```bash venv project_name # activate the project venv pip install ipykernel python -m ipykernel install --user --name project_name ``` -------------------------------- ### Start a Jupyter console with a custom connection file Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Advanced-Functionality.md Starts a Jupyter console with a specified connection file path, avoiding the need to copy the default path. Requires jupyter-console to be installed. ```bash jupyter console --kernel=python3 -f /tmp/your_path_here.json ``` -------------------------------- ### Quarto-nvim sample configuration Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Configure quarto-nvim with LSP features for R, Python, and Rust, diagnostics on BufWritePost, completion, custom keymaps, and Molten as the code runner. Requires the quarto plugin to be loaded for markdown filetypes (e.g., with lazy.nvim use ft = {"quarto", "markdown"}). ```lua local quarto = require("quarto") quarto.setup({ lspFeatures = { -- NOTE: put whatever languages you want here: languages = { "r", "python", "rust" }, chunks = "all", diagnostics = { enabled = true, triggers = { "BufWritePost" }, }, completion = { enabled = true, }, }, keymap = { -- NOTE: setup your own keymaps: hover = "H", definition = "gd", rename = "rn", references = "gr", format = "gf", }, codeRunner = { enabled = true, default_method = "molten", }, }) ``` -------------------------------- ### Automatically import output chunks from Jupyter notebooks (MoltenInit, MoltenImportOutput) Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Sets up autocommands to import output chunks from .ipynb files when opened. It tries to find a kernel matching the notebook's kernelspec, falls back to the active venv name, and prompts for a kernel if none match. Requires Molten's MoltenAvailableKernels, MoltenInit, and MoltenImportOutput commands. ```lua -- automatically import output chunks from a jupyter notebook -- tries to find a kernel that matches the kernel in the jupyter notebook -- falls back to a kernel that matches the name of the active venv (if any) local imb = function(e) -- init molten buffer vim.schedule(function() local kernels = vim.fn.MoltenAvailableKernels() local try_kernel_name = function() local metadata = vim.json.decode(io.open(e.file, "r"):read("a"))["metadata"] return metadata.kernelspec.name end local ok, kernel_name = pcall(try_kernel_name) if not ok or not vim.tbl_contains(kernels, kernel_name) then kernel_name = nil local venv = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") if venv ~= nil then kernel_name = string.match(venv, "/.+/(.+)") end end if kernel_name ~= nil and vim.tbl_contains(kernels, kernel_name) then vim.cmd(("MoltenInit %s"):format(kernel_name)) end vim.cmd("MoltenImportOutput") end) end -- automatically import output chunks from a jupyter notebook vim.api.nvim_create_autocmd("BufAdd", { pattern = { "*.ipynb" }, callback = imb, }) -- we have to do this as well so that we catch files opened like nvim ./hi.ipynb vim.api.nvim_create_autocmd("BufEnter", { pattern = { "*.ipynb" }, callback = function(e) if vim.api.nvim_get_vvar("vim_did_enter") ~= 1 then imb(e) end end, }) ``` -------------------------------- ### Create new notebooks with :NewNotebook command Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Defines a user command to create a blank, valid Jupyter notebook file. The template includes required metadata for Jupytext and defaults to Python 3; change the template for other languages. Use `:NewNotebook folder/notebook_name` to create and open the file. ```lua -- Provide a command to create a blank new Python notebook -- note: the metadata is needed for Jupytext to understand how to parse the notebook. -- if you use another language than Python, you should change it in the template. local default_notebook = [[ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython" }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 5 } ]] local function new_notebook(filename) local path = filename .. ".ipynb" local file = io.open(path, "w") if file then file:write(default_notebook) file:close() vim.cmd("edit " .. path) else print("Error: Could not open new notebook file for writing.") end end vim.api.nvim_create_user_command('NewNotebook', function(opts) new_notebook(opts.args) end, { nargs = 1, complete = 'file' }) ``` -------------------------------- ### Map quarto.runner functions to keymaps Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Maps quarto.runner functions to keymaps for running cells, above, all, line, visual range, and all languages. The run_all(true) call runs all cells of all languages. ```lua local runner = require("quarto.runner") vim.keymap.set("n", "rc", runner.run_cell, { desc = "run cell", silent = true }) vim.keymap.set("n", "ra", runner.run_above, { desc = "run cell and above", silent = true }) vim.keymap.set("n", "rA", runner.run_all, { desc = "run all cells", silent = true }) vim.keymap.set("n", "rl", runner.run_line, { desc = "run line", silent = true }) vim.keymap.set("v", "r", runner.run_range, { desc = "run visual range", silent = true }) vim.keymap.set("n", "RA", function() runner.run_all(true) end, { desc = "run all cells of all languages", silent = true }) ``` -------------------------------- ### Molten configuration for notebook editing Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Configure molten for notebook editing: disable auto-open output, use image.nvim for image outputs, enable wrapping and virtual text output, and adjust virtual lines offset. Requires installing and setting up image.nvim if image outputs are desired. ```lua -- I find auto open annoying, keep in mind setting this option will require setting -- a keybind for `:noautocmd MoltenEnterOutput` to open the output again vim.g.molten_auto_open_output = false -- this guide will be using image.nvim -- Don't forget to setup and install the plugin if you want to view image outputs vim.g.molten_image_provider = "image.nvim" -- optional, I like wrapping. works for virt text and the output window vim.g.molten_wrap_output = true -- Output as virtual text. Allows outputs to always be shown, works with images, but can -- be buggy with longer images vim.g.molten_virt_text_output = true -- this will make it so the output shows up below the ``` cell delimiter vim.g.molten_virt_lines_off_by_1 = true ``` -------------------------------- ### Install Python dependencies with pip Source: https://github.com/benlubas/molten-nvim/blob/main/CONTRIBUTING.md Install all required Python packages into a virtual environment when not using Nix. This command is listed in the 'Without nix' section of the contributing guide. ```bash pip install plotly pnglatex pynvim pyperclip svgwrite sympy tqdm cairosvg ipykernel jupyter_client kaleido matplotlib ``` -------------------------------- ### Minimal molten keybinds Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Set up essential keybinds for molten: evaluate operator and open output window. The output window keybind uses `:noautocmd MoltenEnterOutput` to avoid auto-open behavior. ```lua vim.keymap.set("n", "e", ":MoltenEvaluateOperator", { desc = "evaluate operator", silent = true }) vim.keymap.set("n", "os", ":noautocmd MoltenEnterOutput", { desc = "open output window", silent = true }) ``` -------------------------------- ### Start a Jupyter kernel and get its connection file Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Advanced-Functionality.md Launches a Jupyter kernel with the `jupyter kernel` command. The output shows the connection file path (the important part) and the command to connect a client. Use this to connect Molten to an externally launched kernel. ```bash jupyter kernel --kernel=python3 # [KernelApp] Starting kernel 'molten' # \/ this is the important part # [KernelApp] Connection file: /home/benlubas/.local/share/jupyter/runtime/kernel-5094b45f-58e4-4fdc-9e68-baf52e7e76a9.json # [KernelApp] To connect a client: --existing kernel-5094b45f-58e4-4fdc-9e68-baf52e7e76a9.json # [IPKernelApp] WARNING | debugpy_stream undefined, debugging will not be enabled ``` -------------------------------- ### Install Molten Python dependencies Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Virtual-Environments.md Installs the required Python packages for Molten. pynvim and jupyter_client are mandatory; the rest are optional depending on output types. ```bash pip install pynvim jupyter_client cairosvg plotly kaleido pnglatex pyperclip ``` -------------------------------- ### Set up a Python3 toggle term with toggleterm Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Toggleterm.md Creates a hidden floating terminal running python3 and maps Ctrl+P in normal mode to toggle it. This is the standard setup for a Python3 toggle term. ```lua local python_term = require("toggleterm.terminal").Terminal:new({ cmd = 'python3', hidden = true, direction = 'float'}) vim.keymap.set('n', '', function() python_term:toggle() end, { noremap = true, silent = true }) ``` -------------------------------- ### Configure a Neovim buffer for Quarto notebooks Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Toggleterm.md Builds a command that launches a new Neovim instance, creates an empty virtual buffer, sets filetype to quarto, inserts a template code snippet, adjusts cursor position, loads Molten and Quarto plugins, initializes them, and switches to insert mode. The command uses -c flags and includes a helper function to create markdown code blocks. Initial launch may be slower due to plugin loading. ```lua local function markdown_codeblock(language, content) return '\\`\\`\\`{' .. language .. '}\n' .. content .. '\n\\`\\`\\`' end local quarto_notebook_cmd = 'nvim -c enew -c "set filetype=quarto"' .. ' -c "norm GO## IPython\nThis is Quarto IPython notebook. Syntax is the same as in markdown\n\n' .. markdown_codeblock('python', '# enter code here\n') .. '"' .. ' -c "norm Gkk"' .. -- This line needed because QuartoActivate and MoltenInit commands must be accessible; should be adjusted depending on plugin manager " -c \"lua require('lazy.core.loader').load({'molten-nvim', 'quarto-nvim'}, {cmd = 'Lazy load'})\"" .. ' -c "MoltenInit python3" -c QuartoActivate -c startinsert' ``` -------------------------------- ### Configure nvim-treesitter-textobjects with @code_cell mappings Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Sets up move, select, and swap text objects using the @code_cell captures. Use b for cell navigation (]b, [b), ib/ab for selection, and sbl/sbh for swapping. Swap only works within the same markdown header. Test with vib or run with :MoltenEvaluateOperatorib. ```lua require("nvim-treesitter.configs").setup({ -- ... other ts config textobjects = { move = { enable = true, set_jumps = false, -- you can change this if you want. goto_next_start = { --- ... other keymaps ["]b"] = { query = "@code_cell.inner", desc = "next code block" }, }, goto_previous_start = { --- ... other keymaps ["[b"] = { query = "@code_cell.inner", desc = "previous code block" }, }, }, select = { enable = true, lookahead = true, -- you can change this if you want keymaps = { --- ... other keymaps ["ib"] = { query = "@code_cell.inner", desc = "in block" }, ["ab"] = { query = "@code_cell.outer", desc = "around block" }, }, }, swap = { -- Swap only works with code blocks that are under the same -- markdown header enable = true, swap_next = { --- ... other keymap ["sbl"] = "@code_cell.outer", }, swap_previous = { --- ... other keymap ["sbh"] = "@code_cell.outer", }, }, } }) ``` -------------------------------- ### Activate quarto-nvim in markdown buffers via ftplugin Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Activates quarto in markdown buffers by placing this in nvim/ftplugin/markdown.lua. Requires quarto to be loaded for markdown filetypes (e.g., with lazy.nvim use ft = {"quarto", "markdown"}). ```lua -- file: nvim/ftplugin/markdown.lua require("quarto").activate() ``` -------------------------------- ### Configure jupytext.nvim to convert ipynb to markdown Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Sets up jupytext.nvim to convert ipynb files to markdown (style = "markdown", output_extension = "md", force_ft = "markdown"). This enables quarto-nvim features on the generated markdown files. Note: Quarto format conversion is slower, so markdown is preferred. ```lua require("jupytext").setup({ style = "markdown", output_extension = "md", force_ft = "markdown", }) ``` -------------------------------- ### Keymapping for nested Neovim instances Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Toggleterm.md Creates a toggle term for the Quarto notebook command and maps Ctrl+P in normal and terminal modes. The terminal mode mapping stops insert mode before toggling to prevent nested terminals. This setup allows toggling the Quarto notebook with Molten preloaded. ```lua local molten_term = require("toggleterm.terminal").Terminal:new({ cmd = quarto_notebook_cmd, hidden = true, direction = 'float'}) vim.keymap.set('n', '', function () molten_term:toggle() end, { noremap = true, silent = true }) vim.keymap.set('t', '', function () vim.cmd 'stopinsert' molten_term:toggle() end, { noremap = true, silent = true }) ``` -------------------------------- ### Other Example Mappings for Molten Commands Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Additional keybindings for deleting cells, hiding output, and entering output. The MoltenEnterOutput mapping uses :noautocmd to avoid triggering autocommands. ```lua vim.keymap.set("n", "rd", ":MoltenDelete", { silent = true, desc = "molten delete cell" }) vim.keymap.set("n", "oh", ":MoltenHideOutput", { silent = true, desc = "hide output" }) vim.keymap.set("n", "os", ":noautocmd MoltenEnterOutput", { silent = true, desc = "show/enter output" }) ``` -------------------------------- ### Nixvim plugin configuration for molten.nvim Source: https://github.com/benlubas/molten-nvim/blob/main/docs/NixOS.md Adds molten.nvim via Nixvim's plugins.molten with settings. Exclude lines marked '# for image rendering' if not needed. Settings include auto_init_behavior, image_provider, and output window options. ```nix programs.nixvim = { plugins.molten = { enable = true; # Configuration settings for molten.nvim. More examples at https://github.com/nix-community/nixvim/blob/main/plugins/by-name/molten/default.nix#L191 settings = { auto_image_popup = false; auto_init_behavior = "init"; auto_open_html_in_browser = false; auto_open_output = true; cover_empty_lines = false; copy_output = false; enter_output_behavior = "open_then_enter"; image_provider = "none"; output_crop_border = true; output_virt_lines = false; output_win_border = [ "" "━" "" "" ]; output_win_hide_on_leave = true; output_win_max_height = 15; output_win_max_width = 80; save_path.__raw = "vim.fn.stdpath('data')..'/molten'"; tick_rate = 500; use_border_highlights = false; limit_output_chars = 10000; wrap_output = false; }; }; }; ``` -------------------------------- ### MoltenEnterOutput Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Moves into the active cell's output window. Opens but does not enter the output if it's not open. Must be called with `noautocmd` (see Keybindings for example). ```APIDOC ## MoltenEnterOutput ### Description Moves into the active cell's output window. Opens but does not enter the output if it's not open. Must be called with `noautocmd` (see Keybindings for example). ### Command `MoltenEnterOutput` ### Arguments None ``` -------------------------------- ### Molten-Nvim Wezterm Image Provider Configuration Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Windows.md Example Lua configuration for using Wezterm as the image provider on Windows. Requires the wezterm.nvim dependency and sets vim.g.molten_image_provider = "wezterm". Note that vim.g.molten_auto_open_output must be false when using this provider. ```lua { "benlubas/molten-nvim", build = ":UpdateRemotePlugins", dependencies = "willothy/wezterm.nvim", init = function() vim.g.molten_auto_open_output = false -- cannot be true if molten_image_provider = "wezterm" vim.g.molten_output_show_more = true vim.g.molten_image_provider = "wezterm" vim.g.molten_output_virt_lines = true vim.g.molten_split_direction = "right" --direction of the output window, options are "right", "left", "top", "bottom" vim.g.molten_split_size = 40 --(0-100) % size of the screen dedicated to the output window vim.g.molten_virt_text_output = true vim.g.molten_use_border_highlights = true vim.g.molten_virt_lines_off_by_1 = true vim.g.molten_auto_image_popup = false vim.g.molten_output_win_zindex = 50 end, }, ``` -------------------------------- ### Automatically export output chunks to Jupyter notebook on write (MoltenExportOutput!) Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Adds a BufWritePost autocommand that exports output chunks to the .ipynb file when saving, but only if Molten is initialized. Note that this can cause ~500ms lag when combined with jupytext conversion, and it will prompt for a kernel if more than one is active. ```lua -- automatically export output chunks to a jupyter notebook on write vim.api.nvim_create_autocmd("BufWritePost", { pattern = { "*.ipynb" }, callback = function() if require("molten.status").initialized() == "Molten" then vim.cmd("MoltenExportOutput!") end end, }) ``` -------------------------------- ### Recommended molten keybinds Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Additional keybinds for molten: re-evaluate cell, execute visual selection, hide output, delete cell, and open output in browser. The browser keybind is only needed if you work with HTML outputs. ```lua vim.keymap.set("n", "rr", ":MoltenReevaluateCell", { desc = "re-eval cell", silent = true }) vim.keymap.set("v", "r", ":MoltenEvaluateVisualgv", { desc = "execute visual selection", silent = true }) vim.keymap.set("n", "oh", ":MoltenHideOutput", { desc = "close output window", silent = true }) vim.keymap.set("n", "md", ":MoltenDelete", { desc = "delete Molten cell", silent = true }) -- if you work with html outputs: vim.keymap.set("n", "mx", ":MoltenOpenInBrowser", { desc = "open output in browser", silent = true }) ``` -------------------------------- ### Lua: MoltenRunningKernels Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Returns a list of currently running kernel IDs. Pass `true` to get only kernels in the current buffer; `false` returns all running kernel IDs. ```lua vim.fn.MoltenRunningKernels(true) -- list buf local kernel ids vim.fn.MoltenRunningKernels(false) -- list all kernel ids ``` -------------------------------- ### MoltenDefineCell(start_line, end_line, kernel) Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Takes in a start line, end line, and a kernel and creates a code cell in the current buffer associated with that kernel. Does not run the code or create/open an output window. For compatibility reasons, if there is only one active kernel, you do not need to pass the kernel argument. ```APIDOC ## MoltenDefineCell(start_line, end_line, kernel) ### Description Takes in a start line, end line, and a kernel and creates a code cell in the current buffer associated with that kernel. Does not run the code or create/open an output window. For compatibility reasons, if there is only one active kernel, you do not need to pass the kernel argument. ### Parameters - **start_line** (integer) - Required - The starting line number of the cell. - **end_line** (integer) - Required - The ending line number of the cell. - **kernel** (string) - Optional - The kernel name to associate with the cell. If there is only one active kernel, this can be omitted. ### Usage Example ```lua -- Creates a cell from line 5 to line 10 associated with the python3 kernel vim.fn.MoltenDefineCell(5, 10, 'python3') ``` ``` -------------------------------- ### Disable Pyright reportUnusedExpression diagnostic Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Adds diagnosticSeverityOverrides to the Pyright LSP configuration to suppress the reportUnusedExpression diagnostic, which is commonly triggered by leaving an unused expression at the bottom of a cell to print its value. Add this option to your existing Pyright setup. ```lua require("lspconfig")["pyright"].setup({ on_attach = on_attach, capabilities = capabilities, settings = { python = { analysis = { diagnosticSeverityOverrides = { reportUnusedExpression = "none", }, }, }, }, }) ``` -------------------------------- ### Lua: Get kernel id in MoltenKernelReady Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Use this callback to access the kernel ID when a kernel becomes ready for the first time. The `data` field contains `kernel_id`. ```lua -- ... callback = function(e) print("Kernel id: " .. e.data.kernel_id) end -- ... ``` -------------------------------- ### Template for Quarto IPython notebook Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Toggleterm.md Markdown template inserted into the new buffer, containing a Python code block. This is the content that appears in the toggle term. ```markdown ## IPython This is Quarto IPython notebook. Syntax is the same as in markdown ```{python} # enter code here ``` ``` -------------------------------- ### Start a remote Jupyter console kernel Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Advanced-Functionality.md Launches a Jupyter console on a remote machine with a specified IP and connection file. Used to connect Molten to a remote kernel. ```bash jupyter console --kernel julia-1.7 --ip 1.2.3.4 -f /tmp/remote-julia.json ``` -------------------------------- ### Manual rplugin.vim manifest for Molten on Windows Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Windows.md Paste this into the rplugin manifest file generated by :UpdateRemotePlugins on Windows, where the command may fail to generate it. Edit the file path in the first line to point to your Molten installation, using double backslashes as path separators. The file should be empty except for a few comments before pasting. ```vim " \/ --- This file path call remote#host#RegisterPlugin('python3', '/home/benlubas/github/molten-nvim/rplugin/python3/molten', [ \ {'sync': v:true, 'name': 'MoltenDeinit', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenDelete', 'type': 'command', 'opts': {'bang':''}}, \ {'sync': v:true, 'name': 'MoltenEnterOutput', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenReevaluateCell', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenEvaluateLine', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenEvaluateOperator', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenEvaluateVisual', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenExportOutput', 'type': 'command', 'opts': {'bang': '', 'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenGoto', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenHideOutput', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenImagePopup', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenImportOutput', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenInfo', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenInit', 'type': 'command', 'opts': {'complete': 'file', 'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenInterrupt', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenLoad', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenNext', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenOpenInBrowser', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenPrev', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenReevaluateAll', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenRestart', 'type': 'command', 'opts': {'bang': '', 'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenSave', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenShowOutput', 'type': 'command', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenEvaluateArgument', 'type': 'command', 'opts': {'nargs': '*'}}, \ {'sync': v:true, 'name': 'MoltenEvaluateRange', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenAvailableKernels', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenBufLeave', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenRunningKernels', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenDefineCell', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenOperatorfunc', 'type': 'function', 'opts': {}}, \ {'sync': v:false, 'name': 'MoltenSendStdin', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenTick', 'type': 'function', 'opts': {}}, \ {'sync': v:false, 'name': 'MoltenTickInput', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenOnBufferUnload', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenOnCursorMoved', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenOnExitPre', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenOnWinScrolled', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenStatusLineInit', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenStatusLineKernels', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenUpdateInterface', 'type': 'function', 'opts': {}}, \ {'sync': v:true, 'name': 'MoltenUpdateOption', 'type': 'function', 'opts': {}}, \ ]) ``` -------------------------------- ### Lua: MoltenEvaluateRange with kernel_id Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Pass a string as the first argument to specify a `kernel_id`. This example runs lines 1–23 with the python3 kernel and a column range with the R kernel (`ir`). ```lua -- run lines 1 through 23 (inclusive) with the python3 kernel vim.fn.MoltenEvaluateRange("python3", 1, 23) -- run code starting with col 4 on line 1, and ending with col 20 on line 3 with the R kernel vim.fn.MoltenEvaluateRange("ir", 1, 3, 4, 20) ``` -------------------------------- ### Define @code_cell capture group for markdown in textobjects.scm Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Extends the markdown queries to define @code_cell.inner and @code_cell.outer captures for fenced code blocks. Place this in nvim/after/queries/markdown/textobjects.scm. Required before using the text-object mappings in the Lua config. ```scm ;; extends (fenced_code_block (code_fence_content) @code_cell.inner) @code_cell.outer ``` -------------------------------- ### Lua: MoltenDefineCell Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Creates a code cell in the current buffer from a start line to an end line, associated with the given kernel. It does not run the code or create/open an output window. If only one active kernel exists, the kernel argument can be omitted. ```lua -- Creates a cell from line 5 to line 10 associated with the python3 kernel vim.fn.MoltenDefineCell(5, 10, 'python3') ``` -------------------------------- ### Change Molten settings based on filetype Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md Autocommands to adjust Molten output settings when entering Python files versus Markdown/Quarto/IPYNB files. For Python files, virtual text output is disabled; for Markdown/Quarto/IPYNB files, it is re-enabled. The callback checks if Molten is initialized and updates options accordingly, skipping files with '.otter.' in the name. ```lua -- change the configuration when editing a python file vim.api.nvim_create_autocmd("BufEnter", { pattern = "*.py", callback = function(e) if string.match(e.file, ".otter.") then return end if require("molten.status").initialized() == "Molten" then -- this is kinda a hack... vim.fn.MoltenUpdateOption("virt_lines_off_by_1", false) vim.fn.MoltenUpdateOption("virt_text_output", false) else vim.g.molten_virt_lines_off_by_1 = false vim.g.molten_virt_text_output = false end end, }) -- Undo those config changes when we go back to a markdown or quarto file vim.api.nvim_create_autocmd("BufEnter", { pattern = { "*.qmd", "*.md", "*.ipynb" }, callback = function(e) if string.match(e.file, ".otter.") then return end if require("molten.status").initialized() == "Molten" then vim.fn.MoltenUpdateOption("virt_lines_off_by_1", true) vim.fn.MoltenUpdateOption("virt_text_output", true) else vim.g.molten_virt_lines_off_by_1 = true vim.g.molten_virt_text_output = true end end, }) ``` -------------------------------- ### MoltenInit Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Initializes a kernel for the current buffer. If `shared` is passed as the first value, this buffer will use an already running kernel. If no kernel is given, prompts the user. ```APIDOC ## MoltenInit ### Description Initializes a kernel for the current buffer. If `shared` is passed as the first value, this buffer will use an already running kernel. If no kernel is given, prompts the user. ### Command `MoltenInit` ### Arguments - `shared` (literal) - Optional - If passed as the first value, this buffer will use an already running kernel. - `kernel` - Optional - The kernel to initialize. If not given, prompts the user. ``` -------------------------------- ### User Autocommand: MoltenInitPost Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Runs right after MoltenInit initialization happens for a buffer. Use this to attach buffer-local mappings or other custom behavior after initialization. ```APIDOC ## User Autocommand: MoltenInitPost ### Description Runs right after `MoltenInit` initialization happens for a buffer. ### Event `User` ### Pattern `MoltenInitPost` ### Usage Example ```lua vim.api.nvim_create_autocmd("User", { pattern = "MoltenInitPost", callback = function() vim.keymap.set("v", "r", ":MoltenEvaluateVisualgv", { desc = "execute visual selection", buffer = true, silent = true }) -- ... more mappings end, }) ``` ``` -------------------------------- ### User Autocommand: MoltenInitPre Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Runs right before MoltenInit initialization happens for a buffer. Use this to set up buffer-local mappings or other custom behavior before initialization. ```APIDOC ## User Autocommand: MoltenInitPre ### Description Runs right before `MoltenInit` initialization happens for a buffer. ### Event `User` ### Pattern `MoltenInitPre` ### Usage Example ```lua vim.api.nvim_create_autocmd("User", { pattern = "MoltenInitPre", callback = function() -- custom setup end, }) ``` ``` -------------------------------- ### User Autocommand: MoltenKernelReady Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Runs when a kernel is ready for the first time. The `data` field contains the `kernel_id`. ```APIDOC ## User Autocommand: MoltenKernelReady ### Description Runs when a kernel is ready for the first time. The `data` field contains the `kernel_id`. ### Event `User` ### Pattern `MoltenKernelReady` ### Data Fields - **kernel_id** (string) - The ID of the kernel that is ready. ### Usage Example ```lua vim.api.nvim_create_autocmd("User", { pattern = "MoltenKernelReady", callback = function(e) print("Kernel id: " .. e.data.kernel_id) end, }) ``` ``` -------------------------------- ### User Autocommand: MoltenDeinitPre Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Runs right before MoltenDeinit de-initialization happens for a buffer. Use this to clean up buffer-local state before de-initialization. ```APIDOC ## User Autocommand: MoltenDeinitPre ### Description Runs right before `MoltenDeinit` de-initialization happens for a buffer. ### Event `User` ### Pattern `MoltenDeinitPre` ### Usage Example ```lua vim.api.nvim_create_autocmd("User", { pattern = "MoltenDeinitPre", callback = function() -- custom cleanup end, }) ``` ``` -------------------------------- ### MoltenInfo Source: https://github.com/benlubas/molten-nvim/blob/main/README.md Shows information about the state of the plugin, initialization status, available kernels, and running kernels. ```APIDOC ## MoltenInfo ### Description Shows information about the state of the plugin, initialization status, available kernels, and running kernels. ### Command `MoltenInfo` ### Arguments None ``` -------------------------------- ### Pin image.nvim version Source: https://github.com/benlubas/molten-nvim/blob/main/docs/Not-So-Quick-Start-Guide.md Pin image.nvim to version 1.1.0 for reliability, as the plugin is early-stage and breaks often. Use this in your Lazy plugin spec. ```lua version = "1.1.0", ```