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
    I think you'll need neovim for this. It lets you have a terminal inside a buffer. This way you could have a separate tab just with a terminal. – Al.G. Jul 9 '16 at 10:39
  • 1
    Another solution (the one I use actually) is to use tmux which allows you to split your terminal (e.g. one split for vim and another one for the shell commands). You can also create tabs in your terminal instead of splitting it. Depending on what you are trying to do it could be worth a try. – statox Jul 11 '16 at 15:12
  • You can give :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. – SibiCoder Jul 15 '16 at 13:45

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.

enter image description here

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 pure vim hack, but if not, I'll mark it as the accepted answer. – ArM Jul 13 '16 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. – grochmal Jul 14 '16 at 13:32
  • This answer is out of date in 2020. :tab terminal is probably what you want. It works with vanilla Vim. – 425nesp Jan 25 '20 at 17:27

EDIT: Simpler way is to do :tab terminal, thanks to comment on this post


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
    Even simpler: :tab terminal. – Ralf Jan 31 '19 at 21:04
  • @AlgoRythm & @Ralf, Now the pressing question is: how do we navigate when a terminal has opened in an other tab, Usually I do gt or gT, but it not going to be the case here...... – RaGa__M Jul 2 '20 at 13:48

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
        zle accept-line
        zle push-input
        zle clear-screen

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.


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.