1

In vim 8.2, is there any difference between using :terminal versus :shell to run commands on shell? Or are they identical?

I would like to know if there are any specific use-cases for using :shell vs :terminal where one could be more effective than the other?

To me they kind of looks like almost identical with very slight changes. I am trying to find out the reasoning for having these 2 seperate commands and cases (if there are any) where one might shine over the other.

env variables, initilization steps they all look similar to me. (correct me if I am wrong)

0
2

:terminal spawns a new shell in a Vim window, so you can see a program compiling or producing some output at the same time you edit another normal buffer. Also, by pressing <CTRL-W>N, Vim can operate on the read-only terminal buffer, with yanking, Vim navigation, etc.

:shell also spawns a new shell, but this is a full terminal window shell (it is not in the Alternate Screen as Vim) that won't interacact with the underlying Vim. One can only switch back to Vim by terminating that shell. Unlike :terminal, :shell is not a Vim extension as it is in the POSIX specification of Vi (indirectly, since it is an Ex command), and so a Vim compiled with minimal features (vim-tiny in Ubuntu and Debian) will only have :shell.

:shell is very similar to :suspend/<CTRL-Z>, which uses the shell's job control to suspend Vim. But there are differences:

  • Suspending is impossible in a terminal without a controlling shell (e.g. xterm -e vim).
  • :shell spawns a new shell, which does not have access to Vim's parent shell local values, such as history and variables, whereas each suspenion always brings the same shell back. Indeed, you can toggle between the same shell and Vim with <CTRL-Z> and fg.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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