brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Vim's :terminal opens a shell in a split window

Vim
~/tips/tip-vim-terminal

:terminal

Runs a shell or a command inside Vim, next to your file.

Since Vim 8.1 there is a terminal built in. To run a quick command and keep the file in view, I’d open one in a split.

:terminal
:vertical terminal

:terminal, or just :term, opens your shell in a new window above the current one. :vertical terminal puts it beside it instead. You type in it like in any terminal, and exit closes it.

A few keys start with Ctrl-w in that window. Ctrl-w w jumps back to your file, and Ctrl-w N switches to Terminal-Normal mode, where you can scroll and yank the output with normal Vim keys. Press i to go back to typing.

You can also give it a command to run:

:term ++close make test

That runs the tests in a split, and ++close closes the window again when the command finishes. Without it the window stays, so you can read the output.

It needs a Vim built with +terminal. vim --version | grep terminal tells you; some minimal packages like vim-tiny don’t have it. Neovim has a :terminal too, but its keys and options are different.

A shell running in Vim stops when Vim exits, so long jobs are better off in tmux or a separate terminal.

Further reading: Vim help: :terminal

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link