From 12435bcbd1aa163ceeeaabca80fbedcab54f42ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20P=C3=A1rk=C3=A1nyi?= Date: Thu, 15 May 2025 13:10:52 +0200 Subject: [PATCH] feat(nvim): added molten.nvim for jupyter-like behavior --- nvim/lua/chadrc.lua | 4 +- nvim/lua/configs/lazy.lua | 2 +- nvim/lua/mappings.lua | 19 +++ nvim/lua/myinit.lua | 31 +++-- nvim/lua/plugins/init.lua | 235 ++++++++++++++++++++++---------------- 5 files changed, 179 insertions(+), 112 deletions(-) diff --git a/nvim/lua/chadrc.lua b/nvim/lua/chadrc.lua index 1d1455b..1dc2a81 100755 --- a/nvim/lua/chadrc.lua +++ b/nvim/lua/chadrc.lua @@ -1,7 +1,7 @@ local options = { base46 = { - theme = "catppuccin", -- default theme + theme = "chadracula-evondev", -- default theme hl_add = {}, hl_override = {}, integrations = {}, @@ -11,7 +11,7 @@ local options = { }, }, transparency = true, - theme_toggle = { "catppuccin", "one_light" }, + theme_toggle = { "chadracula-evondev", "one_light" }, }, ui = { diff --git a/nvim/lua/configs/lazy.lua b/nvim/lua/configs/lazy.lua index cd170bd..4e40866 100644 --- a/nvim/lua/configs/lazy.lua +++ b/nvim/lua/configs/lazy.lua @@ -34,7 +34,7 @@ return { "zip", "zipPlugin", "tutor", - "rplugin", + -- "rplugin", "syntax", "synmenu", "optwin", diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index 689e702..743b6b9 100755 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -97,3 +97,22 @@ end, { desc = "Gitsigns Blame line" }) map("n", "td", function() require("gitsigns").toggle_deleted() end, { desc = "Gitsigns Toggle deleted" }) + +-- molten related mappings +map("n", "ip", function() + local venv = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") + if venv ~= nil then + -- in the form of /home/ha5pls/.local/state/virtualenvs/VENV_NAME + venv = string.match(venv, "/.+/(.+)") + vim.cmd(("MoltenInit %s"):format(venv)) + else + vim.cmd("MoltenInit python3") + end +end, { desc = "Initialize Molten for python3" }) +map("n", "mi", ":MoltenInit") +map("n", "me", ":MoltenEvaluateOperator") +map("n", "rr", ":MoltenReevaluateCell") +map("v", "r", ":MoltenEvaluateVisualgv") +map("n", "os", ":noautocmd MoltenEnterOutput") +map("n", "oh", ":MoltenHideOutput") +map("n", "md", ":MoltenDelete") diff --git a/nvim/lua/myinit.lua b/nvim/lua/myinit.lua index 586a13c..8e397ae 100755 --- a/nvim/lua/myinit.lua +++ b/nvim/lua/myinit.lua @@ -15,15 +15,15 @@ vim.filetype.add({ }) -- Hyprlang LSP autocmd({'BufEnter', 'BufWinEnter'}, { - pattern = {"*.hl", "hypr*.conf"}, - callback = function(event) - print(string.format("starting hyprls for %s", vim.inspect(event))) - vim.lsp.start { - name = "hyprlang", - cmd = {"hyprls"}, - root_dir = vim.fn.getcwd(), - } - end + pattern = {"*.hl", "hypr*.conf"}, + callback = function(event) + print(string.format("starting hyprls for %s", vim.inspect(event))) + vim.lsp.start { + name = "hyprlang", + cmd = {"hyprls"}, + root_dir = vim.fn.getcwd(), + } + end }) vim.g.vscode_snippets_path = "~/.config/nvim/snippets" @@ -31,3 +31,16 @@ vim.opt.relativenumber = true vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true + +-- use prepared venv, mostly for molten +local enable_providers = { + "python3_provider", + -- and so on + } + + for _, plugin in pairs(enable_providers) do + vim.g["loaded_" .. plugin] = nil + vim.cmd("runtime " .. plugin) + end + +vim.g.python3_host_prog = vim.fn.expand(os.getenv("XDG_STATE_HOME") .. "/virtualenvs/neovim/bin/python3") diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index 14e1e91..8afe996 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -1,110 +1,145 @@ return { - { - "stevearc/conform.nvim", - -- event = 'BufWritePre', -- uncomment for format on save - config = function() - require "configs.conform" - end, - }, - - { - "neovim/nvim-lspconfig", - config = function() - require "nvchad.configs.lspconfig" - require "configs.lspconfig" - end, -- Override to setup mason-lspconfig - }, - - -- override plugin configs - { - "williamboman/mason.nvim", - opts = { - ensure_installed = { - -- lua stuff - "lua-language-server", - "stylua", - - -- c/cpp stuff - "clangd", - "clang-format", - - -- python - "pyright@1.1.351", -- newer versions have node skill issue - "autopep8", - - -- latex/markdown stuff - "ltex-ls", - "bibtex-tidy", - - -- shell - "shellcheck", - - -- Hyprlang - "hyrpls", - - -- hdl - "rust_hdl", - }, + { + "stevearc/conform.nvim", + -- event = 'BufWritePre', -- uncomment for format on save + config = function() + require "configs.conform" + end, }, - }, - { - "nvim-treesitter/nvim-treesitter", - opts = { - ensure_installed = { - "vim", - "lua", - "html", - "css", - "c", - "cpp", - "markdown", - "markdown_inline", - "yaml", - "python", - "latex", - "vhdl", - "hyprlang", - }, - indent = { - enable = true, - -- disable = { - -- "python" - -- }, - }, + { + "neovim/nvim-lspconfig", + config = function() + require "nvchad.configs.lspconfig" + require "configs.lspconfig" + end, -- Override to setup mason-lspconfig }, - }, - { - "nvim-tree/nvim-tree.lua", - opts = { - git = { - enable = true, - }, - renderer = { - highlight_git = true, - icons = { - show = { - git = true, - }, + -- override plugin configs + { + "williamboman/mason.nvim", + opts = { + ensure_installed = { + -- lua stuff + "lua-language-server", + "stylua", + + -- c/cpp stuff + "clangd", + "clang-format", + + -- python + "pyright@1.1.351", -- newer versions have node skill issue + "autopep8", + + -- latex/markdown stuff + "ltex-ls", + "bibtex-tidy", + + -- shell + "shellcheck", + + -- Hyprlang + "hyrpls", + + -- hdl + "rust_hdl", + }, }, - }, }, - }, - { - "stevearc/conform.nvim", - -- for users those who want auto-save conform + lazyloading! - event = "BufWritePre", - config = function() - require "configs.conform" - end, - }, + { + "nvim-treesitter/nvim-treesitter", + opts = { + ensure_installed = { + "vim", + "lua", + "html", + "css", + "c", + "cpp", + "markdown", + "markdown_inline", + "yaml", + "python", + "latex", + "vhdl", + "hyprlang", + }, + indent = { + enable = true, + -- disable = { + -- "python" + -- }, + }, + }, + }, - { - "godlygeek/tabular", - -- ft = "vhdl", -- temporary solution, but I only need it for vhdl. To be replaced with a real formatter long-term - cmd = { "GTabularize", "Tabularize" }, - -- lazy = false - }, + { + "nvim-tree/nvim-tree.lua", + opts = { + git = { + enable = true, + }, + renderer = { + highlight_git = true, + icons = { + show = { + git = true, + }, + }, + }, + }, + }, + + { + "stevearc/conform.nvim", + -- for users those who want auto-save conform + lazyloading! + event = "BufWritePre", + config = function() + require "configs.conform" + end, + }, + + { + "godlygeek/tabular", + -- ft = "vhdl", -- temporary solution, but I only need it for vhdl. To be replaced with a real formatter long-term + cmd = { "GTabularize", "Tabularize" }, + }, + + { + "benlubas/molten-nvim", + -- version = "^1.0.0", -- use version <2.0.0 to avoid breaking changes + dependencies = { "3rd/image.nvim" }, + build = ":UpdateRemotePlugins", + init = function() + vim.g.molten_image_provider = "image.nvim" + vim.g.molten_use_border_highlights = true + end, + -- lazy = false + }, + { + -- 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", "" }, + integrations = { + markdown = { + enabled = true, + clear_in_insert_mode = false, + download_remote_images = true, + only_render_image_at_cursor = false, + only_render_image_at_cursor_mode = "popup", + floating_windows = false, -- if true, images will be rendered in floating markdown windows + filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here + }, + }, -- do whatever you want with image.nvim's integrations + }, + } }