Magic Wands

Use magic wands! They’re awesome. Learnt about them from rwx.gg (the magic wands is his term)

In command mode, you can hit !! twice, to bring up a prompt which will send the current line to some external command.

For example, if you write:

which docker-compose

and then on that line, type !!bash, it’ll send that to bash, and replace the current line with the output of that command.

/home/sean/.local/bin/docker-compose

Could just as easily send some snippet of code to python or perl, or anything.

This doesn’t have to be on single lines though, you can do 6!! to send 6 lines to some external command.

As an example for vim commands, the keystrokes you’d have to do to write 5 lines to another file would be:

5!!<delete>$:w /tmp/output

the delete is to replace the ! (external vim command) to a $, which specifies a vim command.

The line would look like:

:.,.+4$:w /tmp/foo

The complicated .,.+4 is generated by vim when you do !!5, $:w /tmp/foo is the command I typed in.

I have a script called ix here which accepts some text as STDIN and makes an ix (pastebin), so I can do something like:

5!!ix -v (which becomes :.,.+4!ix -v)

.. which takes those 5 lines and uploads them to ix, copying a link to that paste to my clipboard, without ever leaving vim!