11

I have a terminal command which runs code with a breakpoint in it. When I run this command in NeoVim the code execution does not stop at the breakpoint, instead I get an error, that its not a TTY terminal. The exact same command stops at the breakpoint in Vim.

I guess I need shell command, which was removed in NeoVim. Is there any other way to run it?

:help :terminal shows:

:sh[ell]
Removed. vim-differences

:terminal :te :te[rminal][!] [{cmd}]
Run {cmd} in a non-interactive 'shell' in a new terminal-emulator buffer. Without {cmd}, start an interactive 'shell'.

Type i to enter Terminal-mode, then keys are sent to the job running in the terminal. Type <C-\><C-N> to leave Terminal-mode. CTRL-\_CTRL-N

Update: I have this simple hello_world.py python3 program and I want to make it print "Hello world" (variable name value has to be changed to "world" in the breakpoint:

def hello_world():
    name = None
    breakpoint()
    print(f'Hello {name}')
hello_world()

When I try to execute :!python3 hello_world.py program in the NeoVim I get this output:

:!python3 hello_world.py
> /home/niekas/cct/individual-thematics-api/backend/tmp.py(4)hello_world()
-> print(f'Hello {name}')
(Pdb)
Traceback (most recent call last):
  File "hello_world.py", line 6, in <module>
    hello_world()
  File "hello_world.py", line 4, in hello_world
    print(f'Hello {name}')
  File "hello_world.py", line 4, in hello_world
    print(f'Hello {name}')
  File "/usr/lib/python3.8/bdb.py", line 88, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python3.8/bdb.py", line 113, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit

shell returned 1

Press ENTER or type command to continue

Update: I have tried using :!bash -ic ipython to test if interactive mode works, but it doesn't. IPython exited automatically, see the output:

:!bash -ic ipython
bash: cannot set terminal process group (5377): Inappropriate ioctl for device
bash: no job control in this shell
^[[22;0t^[]0;IPython: individual-thematics-api/backendPython 3.8.5 (default, Jul 28 2020, 12:59:40)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: Do you really want to exit ([y]/n)?
^[[23;0t
Press ENTER or type command to continue
6
  • 3
    You’ll need :terminal in neovim for interactive commands.
    – D. Ben Knoble
    Commented Feb 23, 2021 at 13:32
  • @D.BenKnoble I have tried :terminal, however it does not start in interactive mode if I provide a command. I don't know how to automatically provide a command for terminal, which was started without a command.
    – niekas
    Commented Feb 23, 2021 at 14:24
  • 1
    Actually, the shell is non-interactive, but you can still interact with the command (eg, :terminal python3 is still a python repl). You may have to press i, as you quoted in the post. Without a command, it should just launch a shell—bash, zsh, whatever windows is doing these days, etc. Then you type a shell command—such as the name of a program and its arguments. Maybe you should edit and show how you run the command in vim and neovim and what output you are getting/how its not working?
    – D. Ben Knoble
    Commented Feb 23, 2021 at 14:43
  • If it complains about tty not being a terminal than , the command probably should be run in interactive mode. Try :!bash -ic 'your command ' if you are on bash shell. Or :!zsh -ic 'your command' for zsh shell Commented Feb 23, 2021 at 15:03
  • @JustKhaithang :!bash -ic ipython didn't start in interactive mode for me. See the output in the update question.
    – niekas
    Commented Feb 24, 2021 at 7:07

2 Answers 2

11

Short answer: use :terminal {command} for interactive stuff.

Long answer: neovim’s :! actually communicates via subprocesses and the commands are not directly interactive due to the way the IO streams are handled. :terminal is envisioned as the replacement for this, since it does use a TTY and is interactive.

2
  • :terminal is not useable when you want to run another TUI like gitui - the layout is totally broken and the colors are wrong. Is it possible to hide the nvim "chrome" (status bar, line numbers, commandline) automatically?
    – laktak
    Commented May 9 at 21:43
  • The question ("is it possible to…") seems like you want to How to Ask a question. As for :terminal + gitui, I'm not sure why you deleted your previous question on that, but—I rather suspect it's a bug with the TUI or the neovim terminal. I'm able to comfortably run :terminal htop in Vim, for example. As long as the application and the terminal communicate using, say, the (correct) terminfo entries, everything should work out fine.
    – D. Ben Knoble
    Commented May 10 at 17:52
1

For a smooth transition from Vim to Neovim regarding the handling of interactive terminal commands, try invoking them with my :Silent command. With a trailing bang, the command, say a GUI application like a browser window, is launched in background.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.