hardscrabble 🍫

By Max Jacobson

Psst. Check out my RubyConf 2017 talk, There are no rules in Ruby.

blog posts

my first vim macro

29 Mar 2015

The time has come for me to make a vim macro. Here’s what it looks like in action:

vim macro demo

I made it because I am working on a post that will include a few ruby examples, and I got frustrated typing out Liquid’s verbose syntax for codeblocks (I wish Jekyll supported GitHub-style fenced code blocks). It wasn’t too hard to make it because it’s really simple. I don’t know how to make a smarter one, for example one that puts ruby as the default language, but let’s you start typing immediately to replace it with something else, and then hit tab to jump to the middle (a behavior I’ve seen with snippets in Sublime Text for example).

Here’s what it looks like, straight from my vimrc:

    nnoremap hii i```ruby<ESC>o```<ESC>O

I’ll translate to English:

When I’m in normal mode, and I type hii, act like I typed the following stuff, which I would’ve done if I had typed it out manually:

  • i to go into insert mode
  • type out the first line’s stuff
  • <ESC>o to exit insert mode, create a newline, go to that new line, and go back to insert mode
  • type out the second line’s stuff
  • <ESC>O to exit insert mode, create a newline above the second line, go to that new line, and go back to insert mode

It’s not much and I’m not even sure I’m using the word macro right but it’s mine.

Edit April 2015: Turns out hii was a pretty bad choice, because it starts with h, which I type all the time in normal mode. It’s the left arrow! Whenever I type h now, it doesn’t immediately move left, it hangs a moment while it waits to see if I really mean just h, or if I’m gonna continue and write hii. So, I’ve changed it from hii to <Leader>hii and now I’m happy again.

Note: the default Leader character is \.

managing your Instapaper bookmarks from the command line

22 Mar 2015

I’ve previously written about extracting a gem from a web app called Layabout, but I neglected to mention that I later open sourced Layabout as well:

Today I have the opportunity to write about it, because I finished a kind of fun new feature: a command line interface for efficiently managing your bookmarks. Using it requires cloning the codebase and requesting API credentials, so it’s not a super accessible tool, but for power users it might be worth it. Here’s a quick demo:

bin/rake explore demo

Here’s the code for the CLI as of this moment: https://github.com/maxjacobson/layabout/blob/255eed15be2e55de804083bfdcf8651538af7bb0/lib/tasks/explore.rake

(I like linking to the code as of a certain commit, because who knows, maybe I’ll rename the file later, and then the link to the file on master branch won’t actually work?)

I think it’s kind of interesting code. Each action is an object that describes its help text, the commands it can handle, and how it can handle them.