Vim tip 16: terminal mode
Terminal mode is one way to use shell commands from within Vim.
- :terminal open a new terminal window as a horizontal split
- opens above the current window unless
splitbelow
option is set
- opens above the current window unless
- :vertical :terminal open a new terminal window as a vertical split
- opens to the left of the current window unless
splitright
option is set
- opens to the left of the current window unless
Here are some shortcuts to navigate between windows and change modes:
- Ctrl+w followed by w or Ctrl+w move to the next window
- helps you to easily switch back and forth if you have one text editing window and one terminal window
- see the Splitting tip for more such commands
- Ctrl+w followed by N goes to Terminal-Normal mode which will help you to move around using Normal mode commands, copy text, etc (note that you need to use uppercase
N
here)- Ctrl+\ followed by Ctrl+n another way to go to Terminal-Normal mode
- :tnoremap <Esc> <C-w>N map Esc key to go to Terminal-Normal mode
- Ctrl+w followed by : go to Command-line mode from terminal window
Depending on your shell, you can use the exit
command to end the terminal session. Ctrl+d
might work too.
There are lot of features in this mode, see :h terminal.txt for more details.
Video demo:
See also my Vim Reference Guide and curated list of resources for Vim.