Hardscrabble 🍫

By Max Jacobson

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.


22 Mar 2015

Yesterday morning I grabbed my pants off the floor and a mouse scurried away. I shouted, “ahh!”, ran to my bedroom, and jumped on my bed, pants still in hand.

I had my Improv 201 graduation class performance and I was running late, so I didn’t have time to worry about it. I just got dressed and left with my eyes closed.

On my way to the show, I tried to remember the things we’d been taught over the last 8 weeks, but my mind kept going back to the mouse. It was small and brown; not a startling creature. And yet, very startling!

The show went well, I think. It was fun for me anyway. Afterward we had some food and drinks and then I went home and fell asleep and slept for 15 hours. I wake up around 10am without thinking about the mouse. I’m trying to keep my mind clear, because I’m having a surgery tomorrow, and I want to feel mentally and emotionally prepared so I can be the best patient I can be. And then I start seeing the mouse out of the corner of my eye.

At first it’s to my right, flitting from behind my radiator to behind my couch. I tense up. I pause The Mindy Project. I think it could tell I was occupied.

I resume The Mindy Project. I need to take the last of my antibiotics so I step into the kitchen to take a swig of rice milk. There I see the brown mouse again, by the oven, which is precisely on the other side of the wall from the radiator. I say out loud, “I don’t like this”.

The next time I see the mouse, I’m back at my desktop, and it’s walking back into my living room via the hallway. I say, “hey!” and it turns around and walks back around the corner. I look away and see that he’s walking toward me again. I say “hey, buddy!” and he goes back. So I look away again, and now he’s straight up sprinting past me toward the couch again.

I grab my wallet, keys, and a hoodie, and I leave my apartment and call my mother. She advises me to trap the thing with a glue trap and feel nothing. She says I’ll feel satisfied, like a hunter.

From a nearby cafe I order some humane mouse traps on Amazon.

My grandma calls me and says she’s had good experiences with spring-loaded mouse traps, and that I’ll feel satisfied.

I check a nearby general store. They have glue traps for mice and spring traps for rats. With my grandma still on the phone, I buy the glue trap.

  • 13:15 – I set the traps, one in my hallway and one near the couch, and go sit in bed and watch another sitcom, Undateable, on Hulu. In my field of vision, I can see the first trap.
  • 14:00 – I notice I can see something in the trap and go check on it. It’s just the dab of peanut butter I’d put there earlier.
  • 15:11 – I see the mouse walk right past the trap and into my living room
  • 15:16 – I hear what sounds like panicked squeaking

My mom suggested the mouse would die as soon as it got stuck, of a panic attack, but it just kept squeaking for several minutes while I listened in horror. I feel no satisfaction until later, when I’m sitting in my living room again and nothing scampers through my periphery.