Vim + Python Process + Panel

@Marc has shown us long ago how to integrate
vscode with panel for rapid data exploration.

Personally, I very much prefer vim ( I use Lunarvim )
Here is the corresponding setup if somebody else wants to try it.
(It works on windows with wsl)

  • Install a terminal (I use screen)
  • Install vim-slime
    With Lunarvim, you need to add the following to ~/.config/lvim/config.lua
    lvim.plugins = {
    {
     "jpalardy/vim-slime",
     config = function()
       vim.cmd([[
       let g:slime_default_config = { "sessionname": "julia", "windowname": "0"}
       let g:slime_dont_ask_default = 1
       let g:slime_cell_delimiter = "#%%"
       nmap <leader>a <Plug>SlimeSendCell
       ]])
     end
    },
    


}

* open three terminals:
      1. edit code in vim, with code cells separated by `#%%` lines
      2. open `screen -S julia`  (consistent with the global variables)
          and start a python REPL
      3. open the browser
* to send a code cell from vim to the REPL, use `<SPACE>a`

The image shows the three windows and the code.
The browser window open to the specified port will update
each time the `fig` is updated.

![l|690x459](upload://yVV9sanJwDSoCd0KxivsprRUSSq.gif)
#%%
# Basic Setup: three apps
#   1) edit code in vim editor connected to terminal
#   2) run python REPL in a terminal (I use screen)
#   3) browser window: localhost:<port>   
#
# The editor is connected to screen (and hence the REPL) usin vim-slime
#%%
import holoviews as hv; hv.extension('bokeh')
import panel as pn; pn.extension()
import numpy as np

fig    = pn.Column(pn.panel( "<h1>Figure</h1>"),
                   hv.Curve([1,4,1,9,2,6,-1]) )
                   
server = fig.show(threaded=True, port = 44486)
#%%
x = np.linspace( 0, 10, 100)
h = hv.Curve( x )*hv.Curve(x**2)
fig[1]=h.opts(width=500)
#%%
server.stop()
exit()
1 Like