nvim: Replace slime et al with magma

So far, my repl integration consisted of vim-slime and vim-ipython-cell.
I am basically purely working in the python repl for now and while the
two plugins (together with tmux) *worked* they didn't work well enough
that I used them in an extensive way. Just as often as I could make use
of their productivity enhacements, I had to wrangle with the plugins
themselves to get what I wanted out of them.

Hence the switch to magma. It integrates more deeply into python, and
neovim both - showing cell outputs in floating windows and so on.

It does not, on its own, recognize e.g. jupyter cells or quarto code
cells, so I have set up some simple key binds to improve
inter-operability between those. Especially [r and ]r to jump between
quarto cells and <localleader>R to execute the contents of the cell the
cursor is currently in may be of interest. They are fairly crude and
probably have edge cases where they will not work but until then they
provide an easy quality of life improvement.

Lastly, I silently added a plugin for markdown previews (that also
scrolls with the editing cursor). I don't foresee myself using it *too*
often but it might come handy for smaller articles and writing. It can
be invoked with <localleader>mp - a binding which I will no doubt also
have to overhaul at some point.
This commit is contained in:
Marty Oehme 2023-01-31 10:06:55 +01:00
parent d4bbf7b573
commit 989886a936
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 46 additions and 54 deletions

View file

@ -178,12 +178,13 @@ vim.g.nv_fzf_binds = {
map.n.nore['<leader>n'] = ':NV<cr>'
map.n.nore['<leader>N'] = ':NV!<cr>'
-- Mostly dealing with Prose writing from here on out
-- Format current Paragraph (esp useful in prose writing)
map.n.nore.silent['<localleader>q'] = 'gqap'
map.x.nore.silent['<localleader>q'] = 'gq'
map.n.nore.silent['<localleader>Q'] = 'vapJgqap'
map.n.silent['<localleader>mp'] = '<Plug>MarkdownPreviewToggle'
-- FORMAT code with
-- PLUGIN: formatter.nvim
map.n.nore.silent['<localleader>f'] = ':FormatLock<cr>'
@ -248,21 +249,22 @@ map.n.nore['<leader>ww'] = [[:lua require 'zettelkasten'.index_open()<cr> ]]
-- create a lazygit window, set up in toggleterm settings
map.n.nore['<leader>G'] = ':Lazygit<cr>'
-- PLUGIN: slime and ipython-cell
-- send line / region, not adhering to cells
map.n['<leader>cs'] = '<Plug>SlimeLineSend'
map.x['<leader>cs'] = '<Plug>SlimeRegionSend'
-- send complete script to repl / benchmark execution
map.n.nore['<leader>cr'] = ':IPythonCellRun<cr>'
map.n.nore['<leader>cR'] = ':IPythonCellRunTime<cr>'
-- send current cell / send and go to next
map.n.nore['<leader>cc'] = ':IPythonCellExecuteCellVerbose<cr>'
map.n.nore['<leader>C'] = ':IPythonCellExecuteCellVerboseJump<cr>'
-- clear ipython repl
map.n.nore['<leader>cl'] = ':IPythonCellClear<cr>'
-- jump to previous/ next cell
map.n.nore[']c'] = ':IPythonCellNextCell<cr>'
map.n.nore['[c'] = ':IPythonCellPrevCell<cr>'
-- PLUGIN: magma-nvim
-- Operate jupyter notebooks from within vim
map.n.nore.silent['<localleader>rr'] = ':MagmaEvaluateLine<cr>'
map.n.nore.silent['<localleader>R'] = '?^```{<cr>jV/```<cr>k:<C-u>MagmaEvaluateVisual<cr>'
map.x.nore.silent['<localleader>r'] = ':<C-u>MagmaEvaluateVisual<cr>'
map.n.nore.expr.silent['<localleader>r'] = "nvim_exec('MagmaEvaluateOperator', v:true)"
map.n.nore.silent['<localleader>re'] = ':MagmaReevaluateCell<cr>'
map.n.nore.silent['<localleader>ro'] = ':MagmaShowOutput<cr>'
map.n.nore.silent['<localleader>rq'] = ':noautocmd :MagmaEnterOutput<cr>'
map.n.nore.silent['<localleader>rc'] = ':MagmaDelete<cr>'
map.n.nore.silent['<localleader>rd'] = ':MagmaInterrupt<cr>'
map.n.nore.silent['<localleader>rO'] = ':lua vim.g.magma_automatically_open_output = not(vim.g.magma_automatically_open_output)<cr>'
-- jump to beginning of previous/ next cell code
map.n.nore[']r'] = '/^```{<cr>}:nohl<cr>'
map.n.nore['[r'] = '?^```n<cr>}:nohl<cr>'
-- insert cell header above/below
map.n.nore['<leader>cO'] = ':IPythonCellInsertAbove<cr>a'
map.n.nore['<leader>co'] = ':IPythonCellInsertBelow<cr>a'

View file

@ -16,11 +16,11 @@ end
local packer_bootstrap = ensure_packer()
-- Compile on plugin edits
vim.api.nvim_create_autocmd({"BufWritePost"}, {
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = "plugins.lua",
command = "PackerCompile",
desc = "Compile plugins after editing plugin list",
group = vim.api.nvim_create_augroup('compilepackages', {clear = true})
group = vim.api.nvim_create_augroup('compilepackages', { clear = true })
})
local use = require("packer").use
@ -42,7 +42,7 @@ require("packer").startup(function()
use 'vifm/vifm.vim' -- integrate file manager
use {
'lewis6991/gitsigns.nvim', -- show vcs changes on left-hand gutter
requires = {'nvim-lua/plenary.nvim'},
requires = { 'nvim-lua/plenary.nvim' },
tag = 'release',
config = function() require('plug._gitsigns') end,
event = "BufRead"
@ -98,52 +98,42 @@ require("packer").startup(function()
-- statusline
use {
'nvim-lualine/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true},
requires = { 'kyazdani42/nvim-web-devicons', opt = true },
config = function() require('plug._lualine') end
}
-- writing
use {'vim-pandoc/vim-pandoc-syntax'}
use {'vim-pandoc/vim-pandoc'}
use {'vim-pandoc/vim-criticmarkup'}
use { 'vim-pandoc/vim-pandoc-syntax' }
use { 'vim-pandoc/vim-pandoc' }
use { 'vim-pandoc/vim-criticmarkup' }
use {
"quarto-dev/quarto-vim",
requires = {{"vim-pandoc/vim-pandoc-syntax"}},
ft = {"quarto"}
requires = { { "vim-pandoc/vim-pandoc-syntax" } },
ft = { "quarto" }
}
use 'micarmst/vim-spellsync' -- personal dict improvements for git sync
use {'folke/zen-mode.nvim', config = require('zen-mode').setup()} -- provide distraction free writing
use { 'folke/zen-mode.nvim', config = require('zen-mode').setup() } -- provide distraction free writing
use 'folke/twilight.nvim' -- provide even distraction free-er writing (lowlight paragraphs)
use 'alok/notational-fzf-vim' -- quickly search through the wiki
use({
"iamcco/markdown-preview.nvim", -- generate an auto-updating html preview for md files
run = function() vim.fn["mkdp#util#install"]() end
})
-- languages
use {'euclidianAce/BetterLua.vim', ft = 'lua'} -- better syntax highlighting for lua
use { 'euclidianAce/BetterLua.vim', ft = 'lua' } -- better syntax highlighting for lua
use 'aliou/bats.vim' -- enable syntax for bats shell-code testing library
-- REPL work
use {
'jpalardy/vim-slime', -- send arbitrary code chunks to REPLs
'WhiteBlackGoose/magma-nvim-goose',
run = ":UpdateRemotePlugins",
config = function()
vim.g.slime_target = 'tmux'
vim.g.slime_paste_file = vim.fn.tempname()
vim.g.slime_default_config = {
socket_name = "default",
target_pane = "{last}"
}
vim.g.slime_python_ipython = 1
vim.g.slime_no_mappings = 1
end
}
use {
'hanschen/vim-ipython-cell', -- send code 'cells' to REPL
ft = "python",
config = function()
vim.g.ipython_cell_highlight_cells_ft = {'python'}
vim.g.ipython_cell_insert_tag = "## Cell"
vim.g.magma_image_provider = "kitty"
vim.g.magma_automatically_open_output = false
end
}
--
-- nvim plugs
use {
'echasnovski/mini.nvim',
@ -173,19 +163,19 @@ require("packer").startup(function()
use {
"nvim-telescope/telescope.nvim",
requires = {
{"nvim-lua/popup.nvim"}, {"nvim-lua/plenary.nvim"},
{"nvim-telescope/telescope-fzf-native.nvim", run = 'make'}
{ "nvim-lua/popup.nvim" }, { "nvim-lua/plenary.nvim" },
{ "nvim-telescope/telescope-fzf-native.nvim", run = 'make' }
},
config = function() require('plug._telescope') end
}
use {
'protex/better-digraphs.nvim',
requires = {{"nvim-telescope/telescope.nvim"}}
requires = { { "nvim-telescope/telescope.nvim" } }
}
-- snippeting
use {"hrsh7th/vim-vsnip", event = "InsertEnter"} -- snippet engine
use {"rafamadriz/friendly-snippets", event = "InsertEnter"} -- many snippets
use { "hrsh7th/vim-vsnip", event = "InsertEnter" } -- snippet engine
use { "rafamadriz/friendly-snippets", event = "InsertEnter" } -- many snippets
-- treesitter
use {
@ -198,7 +188,7 @@ require("packer").startup(function()
use {
'RRethy/nvim-treesitter-textsubjects', -- allows using . and ; to target treesitter branches
config = function()
require'nvim-treesitter.configs'.setup {
require 'nvim-treesitter.configs'.setup {
textsubjects = {
enable = true,
keymaps = {
@ -225,7 +215,7 @@ require("packer").startup(function()
use 'ray-x/lsp_signature.nvim'
use {
'ray-x/navigator.lua',
requires = {'ray-x/guihua.lua', run = 'cd lua/fzy && make'},
requires = { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' },
config = function() require('plug._lsp') end
}
-- and completion
@ -241,7 +231,7 @@ require("packer").startup(function()
}
use {
'aspeddro/cmp-pandoc.nvim',
requires = {'nvim-lua/plenary.nvim', 'jbyuki/nabla.nvim'}
requires = { 'nvim-lua/plenary.nvim', 'jbyuki/nabla.nvim' }
}
require('plug._cmp')