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

How do I send commands from a Vim buffer to an embedded terminal?

Answer

:term then <C-w>N for normal mode

Explanation

Vim 8+ and Neovim have a built-in terminal emulator that runs inside a buffer. You can run shells, REPLs, build tools, and test suites without leaving Vim — and even copy text between your code and the terminal.

Opening a terminal

:term                " Open terminal in a horizontal split
:vert term           " Open terminal in a vertical split
:tab term            " Open terminal in a new tab
:term python3        " Open a Python REPL
:term bash           " Open a bash shell

Terminal mode navigation

Keystroke Action
<C-w>N Switch from terminal mode to normal mode
i or a Return to terminal mode (send keystrokes to shell)
<C-w>w Switch to next window
<C-w>: Enter Vim command mode from terminal
<C-\><C-n> Exit terminal mode (Neovim)

Practical workflow

  1. Split your screen: code on top, terminal on bottom
  2. Edit code in the top window
  3. Switch to terminal with <C-w>j
  4. Run tests, see results
  5. <C-w>k to go back to code

Copying from terminal

  1. Press <C-w>N to enter normal mode in the terminal buffer
  2. Navigate and yank text like any buffer
  3. Switch to your code window and paste

Tips

  • Terminal buffers support syntax highlighting for ANSI colors
  • Use :terminal ++close to auto-close the terminal window when the process exits
  • Map a quick toggle: nnoremap <leader>t :botright terminal<CR>
  • In Neovim, use :TermOpen event for autocmds like setting local mappings
  • The terminal buffer is a real buffer — you can search, scroll, and yank from it

Next

How do I always access my last yanked text regardless of deletes?