Emacs: Friend or Foe?
If you're like me, you find Emacs somewhat intimidating. Well, if you're like me, you've been an exclusive vi user for years, and have always wanted to start using Emacs, but have had trouble doing so. Each time you try to switch over, you find yourself pressing <esc> after every third sentence, which (in Emacs) produces some random, and usually undesirable, result. Once, I was thrown into the infamous “Doctor” mode, which is a simple AI program emulating a psychiatrist. There, I spent a good ten minutes telling Emacs what I thought of it. (The response was, "Perhaps you could try to be less abusive.")
Using one of Emacs' vi-emulation modes isn't of much help, either; none of them seem to handle even basic vi commands appropriately. And if you tend to use less-well-known vi features, you're simply out of luck. (Ever try changing the window size with nnnzwww^? I didn't think so.)
As impossible as it may seem, you can find a place for Emacs in your everyday life. If you have the diskspace and memory (a far-from-negligible detail), I strongly suggest looking into Emacs; it can make your life easier, even if you think that you're perfectly content with vi.
Whether you're accustomed to vi or not, however, the default Emacs configuration on many systems is, well, less than adequate. While many users learn to live with Emacs “out of the box”, I've never been content with that approach. Instead, you can get Emacs to do just about whatever you want it to do. So, let's take a look at some customizations that I've found particularly useful.
All of the customizations discussed here involve editing the Emacs configuration file, which is ~/.emacs by default. This file is written in Emacs LISP (Elisp), which is the internal LISP engine that Emacs uses for nearly everything. For example, keystrokes map to Emacs LISP commands. You can modify the command to be executed for each key sequence, and even write your own Elisp functions to bind to keys.
If you're not a LISP programmer, never fear. Most of the LISP forms described here are quite simple and don't require a degree in artificial intelligence to comprehend.
I do assume that you have at least tried to use Emacs, and know how to get into and out of it, are familiar with the Info documentation system, and so on. If not, fire up Emacs and type Ctrl-h (C-h) followed by t, which will drop you into a tutorial. (From there, you're on your own.) The following customizations work under Emacs 19.24. By the time you read this article, there will more than likely be a newer version available, for which certain things may have changed.
Before we can customize Emacs, we need a customization file. By default this is .emacs in your home directory. (Later, we're going to move the contents of .emacs to another file, so buckle your seatbelt.)
Our first task is to rebind several keys to perform more reasonable actions. Admittedly, several of these key bindings are vi-oriented, but should make sense nonetheless. First of all, I like to page back and forth through the document with C-f and C-b, as in vi. In order to rebind these keys, we'd include these lines in our .emacs file:
; Modify meaning of C-f and C-b (global-set-key "\C-f" 'scroll-up) (global-set-key "\C-b" 'scroll-down)
As you can see, comments in Elisp begin with a semicolon and extend to the end of the line. Here, we invoke the function global-set-key twice; once for C-f and again for C-b. In LISP, expressions are parenthesized. The first item in each list is the name of the function to call, and it is followed by any arguments. The first argument to global-set-key is a string constant, representing the key sequence to bind. The second argument is the name of the Emacs LISP function to bind it to. The function name is single-quoted in order to refer to the function name itself, not the function that it points to.
One question remains: How did we know that scroll-up and scroll-down referred to the Emacs functions to scroll pagewise through the document? Other than reading the documentation, you could find this out by using the Emacs function describe-key (which you can invoke with C-h k). Calling this function and following it with a key sequence will tell you the Emacs function name that the key sequence maps to. If you knew that the Emacs keys C-v and M-v (Meta-v, where “meta” is usually the <esc> key) scrolled back and forth through the document, you could use C-h k to determine the function names for these keys. For example, the sequence C-h k C-v will display the function name bound to C-v.
Here are a few more key rebindings that I use often:
(global-set-key "\C-v" 'end-of-buffer) (global-set-key "\M-v" 'beginning-of-buffer) (global-set-key "\C-p" 'yank) (global-set-key "\C-u" 'undo) (global-set-key "\C-r" 'overwrite-mode)
The first two commands rebind C-v and M-v (which previously scrolled by pages) to move to the beginning and end of the buffer, respectively. The third causes C-p to yank the previously deleted or copied region of text, and the fourth causes C-u to execute the undo command. (I tend to use the Emacs' undo feature quite a bit, and find C-x u or C-_ too cumbersome.) The last command causes C-r to toggle overwrite mode.
There are some caveats associated with rebinding keys in this manner. For one thing, it destroys the previous definition of the key. In many cases, this is fine; as long as you didn't use the key as previously defined. However, the last of the above commands rebinds C-r, which is used to invoke a backwards incremental search; a very useful feature. Before rebinding a key you should be sure that its previous definition doesn't mean much to you.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- New Products
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- Validate an E-Mail Address with PHP, the Right Way
- New Products
- Tech Tip: Really Simple HTTP Server with Python
- Trying to Tame the Tablet
- git-annex assistant
3 hours 4 min ago - direct cable connection
3 hours 26 min ago - Agreed on AirDroid. With my
3 hours 37 min ago - I just learned this
3 hours 41 min ago - enterprise
4 hours 11 min ago - not living upto the mobile revolution
7 hours 2 min ago - Deceptive Advertising and
7 hours 38 min ago - Let\'s declare that you have
7 hours 39 min ago - Alterations in Contest Due
7 hours 40 min ago - At a numbers mindset, your
7 hours 41 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




Comments
Thanks - nice article for an
Thanks - nice article for an new emacs convert (from vi...)
A couple of typos in the code for multiple key sequences:
; Various keys for nuking text (global-unset-key "\C-d")(global-set-key "\C-d g" 'my-nuke-to-end)
(global-set-key "\C-d\C-d" 'my-nuke-line)
which I believe should be:
; Various keys for nuking text(global-unset-key "\C-d")
(global-set-key "\C-dg" 'my-nuke-to-end)
(global-set-key "\C-d\C-d" 'my-nuke-line)
At least that worked for me.
Compare with this..
Ever tried viper mode?