How to map the ESC key on a Macbook Pro to be a VIM warrior

My old Mac died and I needed to get the new Macbook Pro with the touch bar. The touch bar is useless for a developer, just absolutely useless. The first time I went into VIM I felt the pain. No hardware ESCAPE key!

There’s lots of tutorials out there to remap your ESC key to your Caps Lock. The steps that worked best for me are below:

  1. Open System Preferences → Keyboard.
  2. Click the Modifier Keys button in the bottom right-hand corner.
  3. If USB devices are attached, you will need to “Select Keyboard” at the top and choose “Apple Internal Keyboard/Trackpad”
  4. Click the drop down box next to the hardware key that you’d like to remap, and select Escape.
  5. Click OK and close System Preferences.

Some steps pulled from the article No hardware Escape key on new MacBook Pros? Don’t fret, macOS Sierra lets you remap the Escape action to a modifier key

Continue reading

How to search and replace text in Vim

Here’s how to search and replace in vim (also known as “substituting” text).

Let’s say I want to replace the text “this” with the text “that”.  In vim, we can do:

This is saying, from line 1, to the end of the file (represented by $), replace “this” with “that”.  The “g” on the end is to do this multiple times on one line of text if applicable.
So you can mix this up and do it from line 1 to line 10:

Or from line 100 to the end:

Or only the first instance on each line (remove the “g”)

There you go.  Happy Vim substituting!
Continue reading