How do I open a terminal inside Vim?
Answer
:terminal
Explanation
The :terminal command opens an interactive terminal emulator directly inside a Vim window. This lets you run shell commands, build your project, or use command-line tools without ever leaving Vim.
How it works
:terminal(or:termfor short) opens a new terminal in a horizontal split above the current window- The terminal runs your default shell (
$SHELL) - You can type commands, run scripts, and interact with the terminal just like a normal terminal emulator
- Press
<C-\><C-n>to switch from terminal mode back to normal mode, allowing you to scroll, yank text, or navigate the terminal buffer
Example
While editing main.go, you want to run your tests without leaving Vim:
:terminal
A terminal appears in a split above your file. Type go test ./... and see the results. Press <C-\><C-n> to return to normal mode and scroll through the output, or type exit to close the terminal.
Opening in different layouts
:terminal— horizontal split (default):vertical terminal— vertical split:tab terminal— open terminal in a new tab:terminal command— run a specific command instead of a shell (e.g.,:terminal python3)
Tips
- Press
<C-\><C-n>to leave terminal mode and enter normal mode — this lets you scroll, search, and yank text from the terminal output - Press
iorato re-enter terminal mode and continue typing commands - Use
<C-w>Nas an alternative to<C-\><C-n>for entering normal mode from the terminal - Use
<C-w>:to enter command-line mode directly from terminal mode - Use
:terminal ++closeto automatically close the terminal window when the shell exits - Use
:terminal ++curwinto open the terminal in the current window instead of a split - This feature requires Vim 8.1+ or Neovim — older versions of Vim do not include the built-in terminal
- Use
<C-w>commands to navigate between the terminal window and your other splits, just like any other window