I usually work on tabs in Vim, and on many occasions, I end up requiring a shell to do run some command, etc. (Escape
-> :!sh
). Is there any way I can open the shell in only one tab in Vim? I would like to be able to switch between tabs containing the files I'm editing, and the shell. Right now, when I type in :!sh
, all the tabs go away, and are replaced by the shell.
3 Answers
UPDATE AS OF VIM 8 and 9: Vim now has an in-built terminal. It works reasonably on most OSes (at least far more consistently than terminal extensions). For the question at hand. :tab teminal
does the job pefectly. The workarounds are now only needed for Vim 7 and lower.
As AI.G. said neovim
is an option, it has a built in terminal emulator. Yet, if you are not afraid of using a python
based plugin in Vim, have a look at the conque plugin.
conque
can not only run a terminal but almost any interactive command.
You can even exit insert mode in the shell (or lynx
as in the example) and use visual mode to yank into a register.
conque
requires python
, and, if you are not on a *nix OS, also requires cygwin
.
There are some issues with keybindings if you try to run Vim, inside a shell inside a Vim tab.
-
Thanks, I'll give it a try.
neovim
isn't available on my machine, so I'll have to install it. The issue is, since this is for work, and I'm assigned new machines every few weeks, I'll have to keep installing this. I'll keep this open for a while, in case there is a purevim
hack, but if not, I'll mark it as the accepted answer.– ArMCommented Jul 13, 2016 at 18:42 -
@noob_12345 - Well, that is technically a Vim "hack". It starts a new process with a shell (or different command) and uses python to pipe STDIN/STDOUT between both. As for installation of plugins you should really be using a plugin manager, see this answer for an extensive discussion of the three most popular ones. Two of them will download and install plugins on the fly.– grochmalCommented Jul 14, 2016 at 13:32
-
This answer is out of date in 2020.
:tab terminal
is probably what you want. It works with vanilla Vim.– 425nespCommented Jan 25, 2020 at 17:27
You can also have a look at vimshell.vim, which is another shell you can run inside vim.
Otherwise I tend to use <C-Z>
for the Vim
<-->shell
quick switch.
This puts vim in the background and let you run commands your shell. It's quicker than opening a new tab a new shell. fg
can be used to go back to Vim.
Bonus:
If you're using zsh
you can also put this snippet in your configuration:
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
This will call fg
if you press <C-Z>
and there is a job in the background. So you can <C-Z>
<C-Z>
quickly.
EDIT: Simpler way is to do :tab terminal
, thanks to comment on this post
ORIGINAL ANSWER:
I know this is an old post, but if anyone arrived here from google, as I did, you can open a new tab with :tabe
, type :terminal
, which will open a shell in that tab, and then close the empty editor with :q
Not sure if there's a more elegant solution, but this achieves what is asked without any plugins. :terminal
Was introduced to vim in vim 8
-
1
-
@AlgoRythm & @Ralf, Now the pressing question is: how do we navigate when a terminal has opened in an other tab, Usually I do
gt
orgT
, but it not going to be the case here......– RaGa__MCommented Jul 2, 2020 at 13:48
:sh
command to go to shell and then give exit there to return back here. The opened files, buffers , tabs before going to shell will be active now. Unlike:!sh
, this one will be in shell until you wish to. You can return back whenever you want to.