ipython + vim-jukit,导入sys命令不转义双引号

问题描述 投票:0回答:1

在 Windows 10 + powershell 上使用 neovim。 vim-jukit 插件用懒惰的方式安装。我的目的是通过 (neo)vim 获得类似 Jupyter Notebook 的体验

当按

<leader>os
输出 split 时,首先在 nvim 状态行中出现以下消息:

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

然后是以下内容:

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]: 

基本上,看起来

"
并未与
\
一起转义。
import
之前的第一个双引号开始字符串,然后
C:
驱动器之前的双引号关闭字符串。

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

我读到,在某些情况下无法使用 cmd 转义双引号,但不确定这是否正确或适用于此。

我也一直在挖掘 vim-jukit 文件,并认为我已经找到了调用

<leader>os
(
C:/Users/$USER/AppData/Local/nvim-data/lazy/vim-jukit/autoload/jukit/splits.vim
)

时传递给 ipython 的命令所在的位置

我认为该文件中的相关代码块是:

    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

但是我对这里发生的事情有点迷失

有没有办法让双引号转义?或者我在错误的地方寻找解决方案?

谢谢

ipython vim-plugin neovim-plugin
1个回答
0
投票

我将 powershell 作为 vim 的默认终端(vim.opt.shell = 'powershell.exe'),从 init.lua 中删除它解决了问题,与默认的 vim 终端一起正常工作。

Friedrich 检查 shellescape() 的建议看起来也适用,但目前我要回到默认值,因为这是一个简单的修复

© www.soinside.com 2019 - 2024. All rights reserved.