MIKE LEVIN AI SEO

Future-proof your skills with Linux, Python, vim & git as I share with you the most timeless and love-worthy tools in tech through my two great projects that work great together.

Recording vim macro for markdown image insertion

Today I'm hosting a livecasting event to show you how to use vim macros to quickly turn keyworded image files into the markdown required for HTML image insertion. I'll be demonstrating how to use search & replace patterns to capitalize and separate words, so you can learn how to quickly add images to your blog posts. Join me to learn this time-saving technique!

Learn How to Quickly Insert Images into Your Blog Posts with Vim Macros!

By Michael 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
s/\<./\u&/g

# Proper-case capitalize everything under visual selection
s/\%V\<./\u&/g

# 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.

Categories