From 981c4cbf10998a0899f5b8b89b0034bd9150691b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 15 Dec 2021 17:28:45 +0100 Subject: [PATCH] Add vim-slime and vim-ipython-cell Added interactive python repl commands with two plugins: Sending repl snippets over with vim-slime and interacting with python (notebook-like) snippets in the editor with vim-ipython-cell. Cells are simply demarcated by `## ` at the beginning of a line, though they can have other syntaxes as well, e.g. `# %% `. By default slime sends its commands over to the last used tmux pane so it is easy to set up a split coding/repl-ing session. Interaction mappings all center around c + another key. You can send a simple cell with `cc` or `C`, single lines or selections with `cs`. You can switch between cells with `]c` `[c` and insert new ones below/above existing ones with `co` `cO` respectively. --- nvim/.config/nvim/lua/maps.lua | 29 +++++++++++++++++++++++------ nvim/.config/nvim/lua/plugins.lua | 26 +++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index 3196360..f0e8278 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -71,16 +71,14 @@ map.n.nore[']a'] = ':next' map.n.nore['[b'] = ':bprevious' map.n.nore[']b'] = ':bnext' -- Quickfix list -map.n.nore['[c'] = ':cprevious' -map.n.nore[']c'] = ':cnext' +map.n.nore['[q'] = ':cprevious' +map.n.nore[']q'] = ':cnext' -- Location list map.n.nore['[l'] = ':lprevious' map.n.nore[']l'] = ':lnext' -- Hunks (from gitsigns) -map.n.nore.expr['[h'] = - [[&diff ? ']c' : 'lua require("gitsigns.actions").prev_hunk()']] -map.n.nore.expr[']h'] = - [[&diff ? '[c' : 'lua require("gitsigns.actions").next_hunk()']] +map.n.nore.expr['[h'] = [[&diff ? ']c' : 'Gitsigns prev_hunk']] +map.n.nore.expr[']h'] = [[&diff ? '[c' : 'Gitsigns next_hunk']] -- set our leader key to space since with hjkl, space is largely useless vim.g.mapleader = " " @@ -257,3 +255,22 @@ map.n.nore['ww'] = [[:lua require 'zettelkasten'.open_index() ]] -- PLUGIN: toggleterm.nvim -- create a lazygit window, set up in toggleterm settings map.n.nore['G'] = ':Lazygit' + +-- PLUGIN: slime and ipython-cell +-- send line / region, not adhering to cells +map.n['cs'] = 'SlimeLineSend' +map.x['cs'] = 'SlimeRegionSend' +-- send complete script to repl / benchmark execution +map.n.nore['cr'] = ':IPythonCellRun' +map.n.nore['cR'] = ':IPythonCellRunTime' +-- send current cell / send and go to next +map.n.nore['cc'] = ':IPythonCellExecuteCellVerbose' +map.n.nore['C'] = ':IPythonCellExecuteCellVerboseJump' +-- clear ipython repl +map.n.nore['cl'] = ':IPythonCellClear' +-- jump to previous/ next cell +map.n.nore[']c'] = ':IPythonCellNextCell' +map.n.nore['[c'] = ':IPythonCellPrevCell' +-- insert cell header above/below +map.n.nore['cO'] = ':IPythonCellInsertAbovea' +map.n.nore['co'] = ':IPythonCellInsertBelowa' diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index c375374..de16ac9 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -36,7 +36,12 @@ require("packer").startup(function() 'lewis6991/gitsigns.nvim', -- show vcs changes on left-hand gutter requires = {'nvim-lua/plenary.nvim'}, tag = 'release', - config = function() require('gitsigns').setup() end, + config = function() require('gitsigns').setup{ + keymaps = { + ['n ]c'] = nil, + ['n [c'] = nil, + } + } end, event = "BufRead" } use { @@ -124,6 +129,25 @@ require("packer").startup(function() -- languages use {'euclidianAce/BetterLua.vim', ft = 'lua'} -- better syntax highlighting for lua + -- REPL work + use { + 'jpalardy/vim-slime', -- send arbitrary code chunks to REPLs + ft = "python", + config = function() + vim.g.slime_target = 'tmux' + 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" + end, + } + -- -- nvim plugs use 'Iron-E/nvim-cartographer' -- makes it easier to set mappings through lua