How to open a terminal in new tab from VIM?

:tab ter

opens a terminal in a new tab instead of opening it in a new window as :ter does. You can also use the equivalent, longer :tab terminal form.

Credits to user wolloda in this Reddit post.

Extra information

  • Terminating the shell with Ctrl-d or exit closes the terminal buffer.

  • Ctrl-w N or Ctrl-\ Ctrl-n put the buffer in the terminal-normal mode: Keystrokes are not forwarded to the shell, but are used by Vim as in a normal buffer (although the shell job is still running). Then you can use gt to change tabs, type Ex commands such as :ls, etc. To bring the terminal buffer back to life, i, a, ...

  • If you are going to map this, I recommend using :tab ter++kill=hup, so that when you :qa the terminal job does not prevent Vim from quitting. And this is the signal normal terminal emulators send to its jobs when closed anyway.

  • For terminal mode mappings, use tnoremap, for example

    tnoremap <S-Tab> <C-W>:tabprevious<CR>
    tnoremap <C-N>   <C-W>N
    

More information on :help :terminal and :help :tab.


In 2019, vim now has a Terminal mode.

:help terminal

For example, you can use it like this.

# go to terminal-job mode
:terminal

# go to terminal-normal mode
ctrl-w N

# go back to terminal-job mode
i

Tags:

Vim