vimtricks.wiki Concise Vim tricks, one at a time.

How do I open a terminal in the current window instead of a new split?

Answer

:terminal ++curwin

Explanation

By default, :terminal opens a new split window for the terminal emulator. If you want to replace the current buffer with the terminal instead of splitting, the ++curwin option tells Vim to reuse the current window.

How it works

  • :terminal — opens Vim's built-in terminal emulator
  • ++curwin — a window modifier that forces the command to use the current window rather than creating a new split

This is particularly useful when you want to quickly drop into a shell without rearranging your window layout, especially if you already have a carefully arranged split setup.

Example

Suppose you have a two-window split layout and want to run a shell command without adding a third window:

┌──────────────┬──────────────┐
│  file1.py    │  file2.py    │
│              │              │
└──────────────┴──────────────┘

Running :terminal ++curwin in the left window replaces it with a terminal:

┌──────────────┬──────────────┐
│  $ _         │  file2.py    │
│  (terminal)  │              │
└──────────────┴──────────────┘

Tips

  • Use ++curwin with a command to run it directly: :terminal ++curwin python3 script.py
  • When the terminal job finishes, the buffer remains — press <CR> or run :bdelete! to close it
  • To return to normal mode inside the terminal, press <C-\><C-n>
  • You can also use ++hidden to open a terminal in a hidden buffer without any window

Next

How do I ignore whitespace changes when using Vim's diff mode?