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
- Split your screen: code on top, terminal on bottom
- Edit code in the top window
- Switch to terminal with
<C-w>j - Run tests, see results
<C-w>kto go back to code
Copying from terminal
- Press
<C-w>Nto enter normal mode in the terminal buffer - Navigate and yank text like any buffer
- Switch to your code window and paste
Tips
- Terminal buffers support syntax highlighting for ANSI colors
- Use
:terminal ++closeto auto-close the terminal window when the process exits - Map a quick toggle:
nnoremap <leader>t :botright terminal<CR> - In Neovim, use
:TermOpenevent for autocmds like setting local mappings - The terminal buffer is a real buffer — you can search, scroll, and yank from it