Thomas Browne
Thomas Browne

Reputation: 24908

Why does Neovim not allow me to run an IPython embed when I run it in a shell?

In my init.vim for Neovim, I have the same line as in my .vimrc in Vim, which, when pressing F12, runs the file currently in the buffer using the python3 interpreter:

autocmd FileType python nnoremap <silent> <F12> :!clear;python3 %<CR>

Now I'm trying to run this tiny "test.py" script by pressing F12 in normal mode:

import IPython
IPython.embed()

Works fine in Vim:

enter image description here

But doesn't work in neovim despite exactly the same line in my ~/config/nvim/init.vim:

enter image description here

So it does run IPython, but then immediately (red arrow) inexplicably asks if I want to exit. It's also got a bunch of weird escape sequences inserted (yellow arrow) which I suspect are the reason why it wants to exit, and which don't appear with normal vim.

I don't really like the internal neovim terminal, so how can I get neovim to behave exactly like vim in this case?

Upvotes: 1

Views: 821

Answers (1)

filbranden
filbranden

Reputation: 8898

This is a known limitation of NeoVim, :! is non-interactive and it will not allocate a pseudo-terminal which is typically required for full-screen applications such as IPython to run properly.

See issue #1496 for details.

An alternative is to use NeoVim's (or Vim 8's) support for terminal, with the :terminal command, or with a function such aa termopen() (in NeoVim) or term_start() (in Vim 8) to run full-screen applications such as IPython.

In your case, something as simple as :term python3 %, running the command in a terminal in a split, might be an adequate replacement.

You might also find the vim-bang-terminal plug-in interesting. It replaces a :! command with a similar command invocation that runs inside a Vim/NeoVim terminal instead.

Upvotes: 3

Related Questions