Future-proof your tech-skills with Linux, Python, vim & git as I share with you the most timeless and love-worthy tools in tech — and on staying valuable while machines learn... and beyond.

Recording vim macro for markdown image insertion

by Mike Levin

Thursday, May 19, 2022

This post is for a livecasting performance art event of recording a very important vim macro: turning a keyworded-image-file.jpg into the full markdown required for html image insertion.

This is what we’re trying to accomplish, starting with alt-text.jpg

![Alt text](alt-text.jpg)

Here is a more specific example: chicken-hawk-from-foghorn-leghorn.jpg needs to become:

![Chicken Hawk From Foghorn Leghorn](/assets/images/chicken-hawk-from-foghorn-leghorn.jpg)

This is the vim search & replace patterns that I built-up. The difference between the first and the second example is the addition of the \%V which tells vim to restrain the search & replace operation you’re about to do to the visual selection. That was tricky!

# Proper-case capitalize everything on line

# Proper-case capitalize everything under visual selection

# Replace hyphens in everything under visual selection
s/\%V\-/ /g

Recording vim macros as performance art

And you can see my .vimrc file on Github.