How do I scroll and copy text from a terminal buffer in Vim?
Answer
<C-w>N
Explanation
When using Vim's built-in :terminal, the buffer is in Terminal-Job mode by default, meaning all keystrokes go to the running shell. Pressing <C-w>N switches the terminal buffer into Terminal-Normal mode, where you can scroll, search, yank text, and use all normal mode commands on the terminal output.
How it works
<C-w>Nswitches from Terminal-Job mode to Terminal-Normal mode- In Terminal-Normal mode, the terminal output becomes a read-only buffer you can navigate freely
- Use standard motions like
gg,G,/pattern,yyto browse and copy output - Press
iorato return to Terminal-Job mode and resume interacting with the shell
Example
" Open a terminal
:terminal
" Run a long command that produces lots of output
" Press <C-w>N to enter Normal mode
" Now you can:
/error " search for 'error' in terminal output
yy " yank a line
gg " scroll to the top
" Press i to go back to the shell
Tips
- In Neovim, the equivalent shortcut is
<C-\><C-n>instead of<C-w>N - You can yank text from the terminal buffer and paste it into other buffers using registers
- This is especially useful for copying error messages, log output, or command results without leaving Vim