Emacs Commands Work in OS X, How Awesome is That?

by James R. Stoup Jul 07, 2008

In the beginning, there was Assembly, and from it flowed many programs. And the programmers of the day looked upon what they had wrought and judged it to be...a freaking pain in the neck. But it worked, and you don't just throw away something that works. However, it only took that first programmer about 15 minutes working with Assembly to realize that something better was needed. He might not have known what, exactly, was needed, but he knew it was something. And so began the drive to develop a better language. Eventually that language was created. Shortly thereafter, a better text editor was demanded. Which just proves that old adage about how if you give a programmer a cookie he is going to ask for glass of milk and a text editor that can handle regular expressions. But I digress.

There are two very old, very powerful text editors out there, one of which is emacs and the other which is not emacs. Some of you out there have chosen the path of the enlightened and learned emacs. Some of you have not. Yes, though it may be inconceivable, vi is still in use. Not by me, but, if rumors are to be believed, by someone.

But wait. I know there will be those who insist that much can be gained by choosing the other path and learning vi. To those people I would calmly point out that I'm already married and thus have no need for any more pain in my life. (Honey, you know that was a joke. I love you, really.) But enough talk of vi, today the subject is emacs. Or more accurately, how learning emacs can make using OS X a much faster experience.

There are certain emacs commands that can be used in just about any generic text field in OS X. First I will list some commands and then I will explain where they can be used. 

One last thing: every one of these commands starts with the "Control" key, unlike standard OS X commands which start with the "Command" or "Apple" key. So for simplicity I will shorten "Control" to just C. So, the command C-a should be read as "hold the control key and press the button [a]". Now onto the list of commands.


[C-a]  go to start of line
[C-e]  go to end of line
[C-f]  move to the next character
[C-b]  move back one character
[C-p]  move to the previous line
[C-n]  move to the next line
[C-m] insert new line (return)
[C-t]  transpose two characters
[C-k]  cut from cursor to end of line
[C-y]  paste
[C-d]  delete forward
[C-h]  delete backward


These are all really handy commands to have at your disposal. For instance, you open Firefox and type in a URL, but halfway through it you decide you don't actually want to go to that website. You have lots of ways to clear the text you just typed, but one of the quickest ways is to use the aforementioned commands. In this case you would type [C-a] to get to the start of the line and then [C-k] to delete everything you just typed. Congratulations, you just hit 3 keys and saved yourself two whole seconds of using the mouse. And who doesn't like saving time?

Anyway, these commands can be used in any standard text field in OS X. This includes the search bar of almost any application (like Safari or Firefox), widgets like Stickies, the Spotlight search bar, or just about anywhere in Text Edit. 

I realize that this whole exercise seems like a lot of work for not much gain, and for those of you who don't use emacs regularly I must totally agree. But for those few users out there who use both emacs and OS X, you will all get giant nerd-gasms from the coolness of this trick. 

Or maybe that was just me.


  • The Control key used as the web accesskey prefix character can be annoyingly interfering with its Emacs-style command usage, e.g. when composing forum posts.

    In case you’ve missed ‘em, Jacob Rus’ articles are informative:

    Cocoa Text System @ http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html
    Cocoa Text System - Usable Selectors @
    Cocoa Text System - Default System Key Bindings @ http://www.hcs.harvard.edu/~jrus/site/system-bindings.html

    sjk had this to say on Jul 08, 2008 Posts: 112
    Did it in 2.

    oren had this to say on Jul 09, 2008 Posts: 2
  • Command-A Backspace != Control-A Control-K

    sjk had this to say on Jul 09, 2008 Posts: 112
  • But the effect is identical; cleared the line wink

    And relax, I’m a devoted EMACSista, I just didn’t think that was the perfect example.

    oren had this to say on Jul 09, 2008 Posts: 2
  • The effect isn’t necessarily identical because Command-A is Select All.  And James was counting the Control key press; you didn’t count your Command key press.

    Relax what, my intended accuracy?  Both of you might have picked better examples. smile

    sjk had this to say on Jul 09, 2008 Posts: 112
  • Command-A isn’t going to work for something that’s multiple lines, it will delete all of them.

    I don’t use macs so I’m not positive, but I suspect these ubiquitous hotkeys have nothing to do with emacs; these are all readline hotkeys, and mac OS probably uses readline (linux does extensively)

    bob-bob had this to say on Jul 09, 2008 Posts: 12
  • bob-bob: Cocoa Text System key bindings don’t use readline.  Take a look at Jacob Rus’s articles I linked to for detailed information.

    sjk had this to say on Jul 10, 2008 Posts: 112
  • This is indeed one of the best text editors I have ever seen. It makes the content look clear and properly organized, just like the Website SEO rules require it. I am planning to use this text editor further on for content writing in order to achieve the same good results as I had so far.

    Sandy had this to say on Oct 28, 2011 Posts: 7
  • Page 1 of 1 pages
You need log in, or register, in order to comment