ipythonvim-pluginneovim-plugin

ipython + vim-jukit, import sys command not escaping double quotes


Using neovim on windows 10 + powershell. vim-jukit plugin installed with lazy. My intention is to have a jupyter notebook-like experience thru (neo)vim

when pressing <leader>os to output split, first the following message appears in the nvim status line:

[vim-jukit] invalid version number encountered:
[]
[7, 3, 0]
Press ENTER or type command to continue

then the following:

PS C:\Users\$USER\repos\jupyter_projs\py_testin
g> ipython3 -i -c "import sys;sys.path.append(\
"C:\\Users\\$USER\\AppData\\Local\\nvim-data\\l
azy\\vim-jukit\\helpers\");import matplotlib.py
plot as plt;from matplotlib_show_wrapper import
 show_wrapper;plt.show = show_wrapper(plt.show,
 1);plt.show.__annotations__[\"save_dpi\"] = 15
0;from IPython import get_ipython;__shell = get
_ipython();__shell.run_line_magic(\"load_ext\",
 \"jukit_run\");__shell.run_line_magic(\"jukit_
init\", \"C:\\Users\\$USER\\repos\\jupyter_proj
s\\py_testing\\py_testing1.1.ipynb 2 --max_size
=20\");"
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 202
3, 23:49:59) [MSC v.1934 64 bit (AMD64)]       
Type 'copyright', 'credits' or 'license' for mo
re information
IPython 8.13.2 -- An enhanced Interactive Pytho
n. Type '?' for help.
  Cell In[1], line 1
    import sys;sys.path.append(" C:\\Users\\$US
ER\\AppData\\Local\\nvim-data\\lazy\\vim-jukit\
\helpers\);import
                               ^
SyntaxError: unterminated string literal (detec
ted at line 1)


In [1]: 

Basically, it looks like the " is not being escaped with the \. the first double quote before import starts the string, and then the double quote before the C: drive is closing the string.

ipython3 -i -c "import sys;sys.path.append(\"C:\\Users\\$USER\\AppData\\Local\\nvim-data\\lazy\\vim-jukit\\helpers\")

I've read that you can't escape double quotes in some cases with cmd but not sure if that is correct or applicable to this.

I've also been digging thru the vim-jukit files and think I've found where the commands passed to ipython are located when calling <leader>os (C:/Users/$USER/AppData/Local/nvim-data/lazy/vim-jukit/autoload/jukit/splits.vim)

I think the pertinent code block in this file is:

    if use_ipy
        let pyfile_ws_sub = substitute(escape(expand('%:p'), '\'), ' ', '<JUKIT_WS_PH>', 'g')
        let store_png = g:jukit_hist_use_ueberzug ? ' --store_png' : ''
        let cmd = cmd
            \. "from IPython import get_ipython;"
            \. "__shell = get_ipython();"
            \. '__shell.run_line_magic("load_ext", "jukit_run");'
            \. '__shell.run_line_magic("jukit_init", "' . pyfile_ws_sub . ' '
            \. g:jukit_in_style . ' --max_size=' . g:jukit_max_size . store_png
            \. ueberzug_opt . '");'
        if !g:jukit_debug && !g:_jukit_is_windows
            let cmd = cmd . '__shell.run_line_magic("clear", "");'
        endif
    endif

    if g:_jukit_is_windows
        let cmd = shell_cmd . " -i -c \"" . substitute(cmd, '"', g:_jukit_win_escape_char . '"', 'g') . "\""
        return cmd
    else
        let cmd = shell_cmd . " -i -c '" . cmd . "'"
        return cmd
    endif

but I'm a bit lost with what's going on here

Is there a way to get the double quote escaped? Or am I looking for the solution in the wrong place?

Thanks


Solution

  • I had PowerShell as default terminal for Vim (vim.opt.shell = 'powershell.exe'), removing this from init.lua solved the issue, works fine with default vim terminal.

    Friedrich's suggestion to check out shellescape() also looks applicable, but for the time being I'm going back to defaults because it's a simple fix.