Remapping the Keyboard on a new Macbook Pro

I must have an odd keyboard, at least for one that’s paired with a Mac. It’s a Microsoft split keyboard and has a bunch of extra keys that aren’t on a Macbook Pro keyboard, like a dedicated # key and the keys are all over the place compared to the laptop keyboard. But I like it that way.

I’ve heard comments from people who use my laptop and they are confused by how shift-2 doesn’t print @ but ” instead, and the key by the left shift prints \ instead of ~ (which is over by the Return key). They’ll say, “Oh, it’s some sort of PC keyboard?” Well, yeah.

This is not the first time I’ve had to fix my keyboard. A long time ago Justin Mason created a useful Irish Fixed Keyboard Layout, but for some reason with this latest hardware upgrade it wasn’t working exactly as planned. The #, \ and ` keys were mixed up. Luckily, with the help of the Key Codes app I could detect the the key code of the physical key pressed. For example, the key next to the left shift is key code 10 so it was just a matter of editing the keyboard layout in a text editor and changing that to output “\”. Logout and login to refresh and the key works!

What’s odd, is that this keyboard layout has served me well for almost a decade and didn’t need editing, which is why I’m documenting it in this post.

I looked at both Ukelele and Karabiner but the former looked overwhelming (yeah, then I went editing XML by hand..) and the latter doesn’t work in macOS Sierra (there’s a simplified “elements” version for Sierra). Then I thought I should just edit the keyboard mapping directly. 🙂

set -o vi FTW

The Bash command line can be edited using the cursor keys but for the real power user you need to enable Vi mode:

$ set -o vi

Or add it to one of your Bash startup files.

Now, instead of the slow interactive editing you’ll get the command and insert mode of Vi! Users of Vi or Vim will feel right at home. You start in insert mode by default so it feels the same as before. You can type new text, move left and right with the cursor keys and delete text but press ESC and you can do all the things Vi command mode allows you to do.

Check out this extensive cheat sheet with examples or jump directly to the ascii version here!

Some tips to make Mac OS X Finder easier to use

Making the switch from Windows or Linux to Mac OS X is not without pain. The extra CMD key plays havoc with muscle memory, and the “Windows Explorer” of Mac OS X, Finder, is quite a different beast to what you might be used to in the Windows or Linux worlds.

About two weeks ago I decided to make the switch again to Mac OS X and I lamented the difficulty in using Finder to do simple tasks. I’m still not 100% happy with Mac OS X it but the tips on the following pages made things easier:

  • Home and End keys work on a line, not a document, silly.
  • Disable natural scrolling.
  • Switch CMD and ALT if you’re using a PC keyboard. I have a lovely split keyboard but the default configuration hurt my fingers.
  • Change the keyboard layout if your keyboard doesn’t work the way you’re used to. I still haven’t got this set up exactly as I want it to. In my terminal some keys act differently I think but I haven’t set aside time to work out which. I need to swap ” (shift-2) with @ (key to the top/left of right-shift). My muscle memory gets them mixed up all the time.
  • Automount SMB drives automatically. I haven’t been able to get the fstab method to work yet because my password has spaces but the “User Login” one works well enough.
  • Change Finder search so it searches the current directory by default.
  • Type the path into Finder.
  • 9 tips to improve Finder.
  • Sorting and arranging in Finder.
  • Right click on the directory name in Finder and show a dropdown of the path to that directory.
  • Install Mac Ports to get a working copy of Rsync and a better ls that lets me put parameters after the filename.

There are still oddities. When Mac OS X mounts an SMB share it does so with permissions that only allows the current user to edit files in the share. That’s perfectly understandable but it messes things up for Rsync when I’m syncing directories with a remote host. I’ve had to resort to using the “–size-only” parameter of Rsync so it won’t attempt to sync every file each time. I need to figure out if that can be fixed somehow.

I’ll update this post from time to time as I come across more oddities.

Vim's cursor keys work in Mac OS X again

export TERM=linux

Ever since my Macbook died and was fixed again Vim hasn’t worked properly in iTerm.

I’m a big fan of SSH and Screen. SSH to connect to a remote server, and Screen is like a workspace organiser for your SSH session.

First of all the backspace key worked in Vim even when not in insert mode, but worst of all, the cursor keys refused to work and only succeeded in ringing bells in the terminal. Previous attempts at fixing the problem failed but I must have searched for the right terms this time. This review of Mac OS X led me part of the way. Sébastien recommended setting the TERM to “dtterm” but Screen didn’t recognise that. Setting it to “linux” fixes my SSH sessions, and also fixes Vim locally as well!

I added the snippet of code above to my ~/.bash_profile to make the change permanent and everything is back to normal now! I have a vague memory of fixing this before but I wish now I had blogged it then!

How much of your Macbook's battery is gone for good?


Rechargeable batteries start deteriorating from the moment they are manufactured. I’ve noticed my Canon 20D’s batteries don’t last quite as long as they did 2 years ago. AA and AAA batteries seem to be even worse. As I’m heading to San Francisco in July I’ll be doing a lot of flying so it’ll be important that my Apple Macbook laptop have a decent battery life.

There’s no quick fix for this as it’s not reversible but if you’re wondering how much life is left, then Coconut Battery is a must have. I installed it last night and it looks like my battery still has 85% of it’s capacity left after 11 months of use. That’s not bad. It’s not enough to get me across the Atlantic but I don’t know if I want to spend €139 on a second battery when I’ll only ever use it once a year.

I think it is possible to slow down the deterioration. Don’t unplug your laptop! The less you use the battery, the longer the battery will last.

I made my Macbook cry

If Macs are so perfect why do they keep crashing and dying and need to be rebooted seeminly after every update? I’m just back from another reboot when Flock brought the system down. Yes, yes, must switch to another browser but after Mark’s ranting about the slowness and general bloatedness of OS X Firefox I’m wondering what I’ll use.

For all the fans of Microsoft Windows out there, here’s a sort of BSOD from the Mac. This happened at the last BarCamp in Waterford. I have witnesses!


In the interests of fairness, I should also say that Linux died horribly on me when Firefox, Flock, GIMP and Bibblepro were all loaded and swap went haywire. It was quicker to put it out of it’s misery and reboot than wait for the kernel to kill one of the above apps. But why spoil a good anti-Mac rant by injecting some perspective?

How to rename a file in Mac OS X

Silly bugger, doesn’t he know Macs are easy to use? Well, yes they are but it’s not obvious how you can rename a file or folder in Finder. I had to look it up in a book to find out. (Thanks Barry for “The Missing Manual”!)

It is rather simple to rename a file actually, although not obvious.

  • In Finder, open the folder with your file in it.
  • See all those pretty icons? Don’t click on them. Find the icon for your file. Click once on that icon then click and hold the mouse button down on the filename below it.
  • After about a second of holding down the mouse button the text will become editable and you can type over the filename. Be careful you don’t change the extension because bad things will happen!

Simple when you know how.

Meanwhile, Mark is documenting his own experiences with a Mac Mini. Must try X-Chat Aqua.

Mac OS X – how to update /etc/hosts

Way back in the good old days of Linux and Windows it was much easier to update my hosts file. There it was, /etc/hosts or C:\windows\hosts, edit, save and the change becomes active.

MacOS X is a little more complicated. Once you update /etc/hosts you’ll have to update the Netinfo Database. That’s why I’m blogging this so I’ll remember it. This page documents the steps required but the important command is this one:

sudo niload -v -m hosts . < /etc/hosts

There is a GUI but it’s a little clunky and duplicating an existing entry isn’t the most elegant method of adding a new one. Especially when a warning dialog pops up!

Thanks Barry for suggesting a similar fix while I was in SF and getting used to my new laptop! 🙂