1

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually I found that running :term python3 % works fine now for my purposes so it's not as bad as I thought.
@ThomasBrowne Thanks for the feedback! I incorporated that direct suggestion into the answer. Indeed, while not exactly the same as the :! command, it's a great direct replacement for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.