vim-slime
vim-slime copied to clipboard
Failure to start ipython in vim terminal
I'm using the following configuration in my .vimrc
to enable vim-slime and vim-ipython-cell receiving and executing code received from the Python scripts.
.vimrc
" -- IPython Cell / slime config
let g:slime_python_ipython = 1
" map verbose cell execution to ce
nnoremap <LocalLeader>ce :IPythonCellExecuteCellVerbose<CR>
" Start vim slime in vertical terminal
let g:slime_target = "vimterminal"
let g:slime_vimterminal_config = {"term_finish": "close"}
let g:slime_vimterminal_config = { "vertical": 1 }
let g:slime_vimterminal_cmd = "ipython"
My intention is to enable execution of cells in a vertical vim terminal. Working with the script below:
sample_script.py
# %% Define Variable
A = '12 9 61 5 14'.split(' ')
A = map(int, A)
I'm attempting to execute the Define Variable cell. Vim launches terminal correctly, and it seems that attempts to execute the ipython
command. However, ipython
fails to start with the following error message:
i^CTraceback (most recent call last):
File "/Users/konrad/.pyenv/versions/HackerRank/bin/ipython", line 5, in <module>
from IPython import start_ipython
File "/Users/konrad/.pyenv/versions/3.9.4/envs/HackerRank/lib/python3.9/site-packages/IPython/__init__.py", line 55, in <module>
from .core.application import Application
File "/Users/konrad/.pyenv/versions/3.9.4/envs/HackerRank/lib/python3.9/site-packages/IPython/core/application.py", line 18, in <modul
e>
import logging
File "/Users/konrad/.pyenv/versions/3.9.4/lib/python3.9/logging/__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "/Users/konrad/.pyenv/versions/3.9.4/lib/python3.9/traceback.py", line 5, in <module>
import linecache
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 786, in exec_module
File "<frozen importlib._bootstrap_external>", line 918, in get_code
File "<frozen importlib._bootstrap_external>", line 587, in _compile_bytecode
KeyboardInterrupt
%cpaste -q
Question
How to ensure that ipython REPL starts properly in vim terminal when called via vim-slime?
Vim version
vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 30 2022 20:12:27)
macOS version - x86_64
Included patches: 1-4650
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_urxvt -tag_any_white
+arabic +find_in_path +mouse_xterm -tcl
+autocmd +float +multi_byte +termguicolors
+autochdir +folding +multi_lang +terminal
-autoservername -footer -mzscheme +terminfo
-balloon_eval +fork() +netbeans_intg +termresponse
+balloon_eval_term +gettext +num64 +textobjects
-browse -hangul_input +packages +textprop
++builtin_terms +iconv +path_extra +timers
+byte_offset +insert_expand +perl +title
+channel +ipv6 +persistent_undo -toolbar
+cindent +job +popupwin +user_commands
-clientserver +jumplist +postscript +vartabs
+clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +vim9script
+cmdline_hist +langmap -python +viminfo
+cmdline_info +libcall +python3 +virtualedit
+comments +linebreak +quickfix +visual
+conceal +lispindent +reltime +visualextra
+cryptv +listcmds +rightleft +vreplace
+cscope +localmap +ruby +wildignore
+cursorbind +lua +scrollbind +wildmenu
+cursorshape +menu +signs +windows
+dialog_con +mksession +smartindent +writebackup
+diff +modify_fname -sodium -X11
+digraphs +mouse -sound -xfontset
-dnd -mouseshape +spell -xim
-ebcdic +mouse_dec +startuptime -xpm
+emacs_tags -mouse_gpm +statusline -xsmp
+eval -mouse_jsbterm -sun_workshop -xterm_clipboard
+ex_extra +mouse_netterm +syntax -xterm_save
+extra_search +mouse_sgr +tag_binary
-farsi -mouse_sysmouse -tag_old_static
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lm -lncurses -liconv -lintl -framework AppKit -L/usr/local/opt/lua/lib -llua5.4 -mmacosx-version-min=12.0 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.34.0/lib/perl5/5.34.0/darwin-thread-multi-2level/CORE -lperl -L/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin -lpython3.10 -framework CoreFoundation -lruby.3.1 -L/usr/local/Cellar/ruby/3.1.1/lib
hi @konradzdeb
Thanks for reporting this ^
I'll have a look tonight and report back.
hi @konradzdeb
I re-read this and nothing jumps at me. Can you try another target, preferably tmux? Let's try to isolate what works and what doesn't.
If you have a "docker recipe", I could also try to reproduce on side.
Let me know
Hi, thanks for your responsiveness. There is no problem with passing commands to tmux but I've started ipython manually, what would be the equivalent to setup to launch tmux session automatically with ipython running? So far I've
" -- IPython Cell
let g:slime_python_ipython = 1
" map verbose cell execution to ce
nnoremap <LocalLeader>ce :IPythonCellExecuteCellVerbose<CR>
" Start vim slime in vertical terminal
" let g:slime_target = "vimterminal"
" let g:slime_vimterminal_config = {"term_finish": "close"}
" let g:slime_vimterminal_config = { "vertical": 1 }
" let g:slime_vimterminal_cmd = "/Users/konrad/.pyenv/shims/ipython"
let g:slime_target = "tmux"
Hi @konradzdeb
I've been thinking about this problem, and, for now, I'm using this script. What it does:
- creates a file with a generated name,
_vimrepl.EXT
- opens that file in vim
- splits tmux vertically
- starts a REPL in the split
for example:
> vimrepl js -c node
opens _vimrepl.js
with node
in the split. Have a look at the script and use it if it's helpful.
HI @jpalardy ,
The vimrepl
script works as expected when run inside tmux.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.