Skip to content

Integrating Shell Commands Into Vim

Resources

Basics

:.!bash will send the current line to the shell, and replace the line with the command output. bash can be any other shell command.

For example, running :.!python on:

for i in range(3): print(f'{i})')

will replace the line with

0)
1)
2)

More here.

Running on a visual selection

Let's say you have some JSON in a markdown file like this:

{
  "event": {
    "op": "INSERT",
    "something": "else"
  }
}

Visually select the lines containing the JSON content, and run

:'<,'>!jq

Inspiration from this post.

Running on specific range

The above can also be run as:

:10,15!jq