Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

Give Me A Better # Key

This is in reply to Give me back my # key! I was already doing my Vim thing but I didn’t realise I could map keys in readline until I read that article. Thanks Graeme!

If you use a Mac in the UK and often type #, you may find the Option-3 key combo annoying. I do.

Fortunately there’s another key nearby which I never use: the §/± key underneath Escape. We can map that to # and forget about the Option key.

Command line

To sort out your command line, add this to your ~/.inputrc:

"§": '#'

You’ll need to reload your readline configuration, most easily by restarting Bash.


Vim is slightly trickier. We want to map § to # in insert mode and on the command line (for : commands), but not in normal mode where # means the same as * but backwards. So far, so good. But we also want to be able to replace a character with # using , and move forward to the next # with .

Fortunately Ben Schmidt explained to me how to do this. Add this to your ~/.vimrc:

set iminsert=1
set imsearch=-1
noremap  § #
noremap! § #
lnoremap § #


Unfortunately IRB doesn’t pay attention to your ~/.inputrc, as far as I can tell, even though it is supposed to integrate with readline.

If anyone knows how to fix this, I’d love to hear about it!

Andrew Stewart • 7 February 2012 • DevelopmentOSX
You can reach me by email or on Twitter.