Access to the terminal while you are on Vim

29,585

Solution 1

You can send vim the SIGTSTP signal. You do this by pressing ctrl+z. Vim will get suspended in the background, and you can use the terminal. Type fg in the terminal to resume with vim.

Bonus tip: This works on nearly all terminal applications. Use bg to enable the application to continue running in the background.

Solution 2

In vim, just type:

:!sh

:! launches an external process -- in this case sh, another shell. Control will return to vim once you exit the shell. If you want to use the shell concurrently with vim, add & to the end of the sh command:

:!sh&

Solution 3

You can use the :shell command (or the short form :sh). From :help :shell:

This command starts a shell. When the shell exits (after the "exit" command) you return to Vim. The name for the shell command comes from 'shell' option.

By default, on Ubuntu, this will give you bash. type exit to return to vim when you're done.

Solution 4

Since recent vim you can now do:

:terminal

This was initially added in Vim 8.0.693, but with lots of bugs. See :help terminal:

WARNING: THIS IS ONLY PARTLY IMPLEMENTED, ANYTHING CAN STILL CHANGE

The terminal feature is optional, use this to check if your Vim has it: 
        echo has('terminal')
If the result is "1" you have it.   

[...]

The terminal feature requires the +multi_byte, +job and +channel features.

==============================================================================
1. Basic use                                            terminal-use

This feature is for running a terminal emulator in a Vim window.  A job can be
started connected to the terminal emulator. For example, to run a shell: 
     :term bash

Or to run a debugger: 
     :term gdb vim

The job runs asynchronously from Vim, the window will be updated to show
output from the job, also  while editing in any other window.

Solution 5

As addition to all answers.

You can install ConqueTerm plugin

This plugin provide ability to run interactive programs inside vim buffers.

After installation you can add this 2 lines to your .vimrc:

:nnoremap <S-w> :q!<CR>
:nnoremap <S-t> :ConqueTermSplit bash<CR>

And you will be able to run bash by pressing Shift + T, and close current Conque tab by pressing Shift + W

It is perferct if you need fast open/close bash.

Here is gif that showing how it is look like

Share:
29,585

Related videos on Youtube

Mohammad Reza Rezwani
Author by

Mohammad Reza Rezwani

Msc of computer networks.

Updated on September 18, 2022

Comments

  • Mohammad Reza Rezwani
    Mohammad Reza Rezwani over 1 year

    Is there a way to access the terminal while using Vim?

    I do not like to open another terminal or save and exit the current terminal.

    • Wilf
      Wilf almost 10 years
      Open a new tab? (Ctrl + Shift + T)
    • Mohammad Reza Rezwani
      Mohammad Reza Rezwani almost 10 years
      How many times do that :) I do not like to do that D:
    • jrg
      jrg almost 10 years
      Have you tried using a terminal window manager like tmux?
  • wchargin
    wchargin almost 10 years
    Or just use :shell.
  • Frank Conry
    Frank Conry almost 10 years
    This is the best answer for most purposes.
  • dman
    dman almost 10 years
    I vote for the ^z (and later fg) method, because this can be used in almost all shell processes - it's not a vim thing, it's a how-to-use-shell trick that is incredibly useful in other contexts.
  • Josh
    Josh over 7 years
    That's nice but what about when the command is running a server, like http-server and it prints out logs that I want to view? I'd like to be able to switch over to my files, make edits, then switch back to the logs.
  • ggulgulia
    ggulgulia over 5 years
    can you please consider updating the posts? The links you mentioned seems outdated