Skip to content

Vim-fu: Recording a macro

I’ve been using MacVim a lot more to try and move towards a keyboard-centric means of computer usage; because I dream of one day this year writing about how I’ve finally mastered coding by voice, mastering command-and-control without point-and-click is a first step. To get up and running on “vim, with training wheels” I used the Janus project to install a bunch o plugins to help as I get better.

The next step (well, somewhere in the n steps to master vim-fu) for me to master keyboard-only interactions as a bridge to voice, or possibly gesture, interactions is to make some shortcuts for myself. Here’s a line that I write a lot:

require 'pry'; binding.pry

Ah, yes, pry. It’s pretty much the number one gun in my Ruby hustler belt. When in doubt, pry. The line above is what I’ll add to code to let myself step into it, analogous to debugger; in the browser. So, to save my ulnar nerve, I made a shortcut. At least, as far as I can tell, the recording works for a session in vim.

Step 1: Start recording in a register

Type q [letter] to store your macro in a register. I stored mine in a so it’d be easy.

Step 2: Do things

Do whatever you need, anything really. For me, I opened a new line, wrote the pry line, and that was it.

Step 3: Stop recording

Hit q

Step 4: … profit?

Use your recording with @[key], so @a in my case. And tada!

I probably missed some intricacies, and would love to hear any tips!

 

 

One Reply to “Vim-fu: Recording a macro”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.