3

There is no :shell command in neovim. :terminal opens a shell without previous output, while :shell contains all the output of the parent shell and all previous shells. Is there any way to emulate :shell behavior with :term?

1
  • 8
    It would be useful to give us more details on your use case and why you want :shell instead of :terminal. Maybe using CTRL-z to put neovim in background and then using fg to bring it back would be what you want? :h CTRL-Z
    – statox
    Apr 23, 2019 at 7:14

4 Answers 4

2

As @statox mentioned, you can use CTRL-z. If you want to spawn a new shell from vim, as :shell does, you can do: :!sh, :!bash, :!zsh (pick your favourite), which has pretty much the same effect as :shell.

4
  • 1
    thanks @padawin - but when I enter :!sh in nvim I just see "Press ENTER or type command to continue" in the status line, but not the interactive shell I get when entering :shell in vim (or also :!sh). Any ideas?
    – Red Pill
    Oct 25, 2019 at 8:00
  • 2
    :! will not work with interactive commands. The closest you will get to vim's :shell is probably using CTRL-z.
    – crater2150
    Oct 25, 2019 at 11:14
  • How do I get back to neovim after C-z? Jul 19, 2022 at 4:18
  • 1
    @QuaziIrfan RE "get back to neovim:" Depends on your system. If invoking nvim from Bash. In nvim, we press CTRL-z, which temporarily stops nvim and returns to the Bash prompt. One way to get back to nvim is to invoke jobs, find the jobspec for nvim, then invoke fg with the jobspec as the argument to fg. See also man bash or in GNU Bash manual
    – Ana Nimbus
    Aug 2, 2022 at 13:56
1

In your init.lua you can set vim.o.shell to the shell binary you're using in your parent shell. For bash that's usually /bin/bash & for zsh /bin/zsh.

vim.o.shell = '/bin/zsh -i'
0

My solution for this need of shell integration is to use neovim terminal tab as main shell.

I use also skywind3000/vim-terminal-help plugin and drop command to open new files in same instance of vim and not in nested ones.

0

It should be possible to attach to a tmux session from the terminal, i.e. :term tmux a. I'm not sure how usable it will be, but it's one way to get a persistent shell from neovim.

1

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.