Learning GNU Emacs, 3rd Edition
For a programmer, it is reasonable to question whether or not a word processor or graphical IDE is the right tool to edit a simple script or properties file. IDEs like Eclipse have become universals hammers, and to some of their users, any file containing text looks like a nail. Specific tasks are rarely handled well by universal tools, and text editing is no exception. Dave Thomas and Andy Hunt, authors of The Pragmatic Programmer and founders of the Pragmatic Bookshelf series, recommend that programmers adopt a text editor as an essential utility in their collection of appropriately-suited tools. The tried-and-true text editor is enjoying a renaissance of sorts, and one of the most extensible and customizable applications among text editors is the venerable GNU Emacs.
Tutorials and documentation for Emacs are abundant, but they often prove time-consuming and ineffective for actually learning Emacs. The printed version of the official GNU Emacs manual reads more like an application programming interface (API) document than an instructional guide. This book is a refreshing break from the documentation many have come to expect. Imagine having a group of leading experts on Emacs at your disposal to teach you how to use it in a conversational, consultative style. That is what has been bundled into this book.
The extensibility of Emacs is considered both a key strength and a confusing weakness of the application. The Emacs community has created all sorts of additional capabilities for Emacs, ranging from the impressive to the absurd. The authors have done well to judiciously select which Emacs capabilities to cover. For example, while Emacs does have the capability to function as an email client, other applications have long superseded its ability. The authors have chosen not to cover this topic, and instead devote the available space to learning Emacs' core functionality -- powerful, efficient text editing.
This edition of the book uses the space gained by the removal of esoteric topics to flesh out areas of more common interest. Peripheral areas of Emacs, such as compatibility modes for programming languages (other than Java and Perl), have been left for the user to research after gaining a solid foundation on Emacs as editor and work environment. Integration with the major version control systems has been expanded to include Subversion alongside the age-old standards CVS, RCS, and SCCS. Coverage of support for Java and Perl has also improved, as well as sections for editing HTML and XML. Users wanting to tap into the power of Lisp programming for Emacs should find the coverage satisfying as well.
The pace of the material is comfortable, and the order in which topics are introduced allows the user to progress smoothly through the book. Users with some experience can skip past the first three chapters, but would be advised to read through them, particularly those who are self-taught (which applies to most Emacs users). Given the amount of time the average user spends in Emacs, picking up one or two time-saving shortcuts would be well worth an investment of a few hours. Instructions are given in a way that reflects the fact that there are multiple ways to achieve the same outcome; the authors do not attempt to foist "the only way" to accomplish something upon the reader. Some readers will find that bothersome, desiring instead a simple, straightforward heuristic for performing a task. However, the typical users of Emacs tend to be people who embrace the fact that the world is not a simple, straightforward abstraction. The book reflects the authors' awareness of this nuance.
Perhaps the most distinguishing feature of this book is the chapter devoted to the use of Emacs on different platforms. Unix, Windows and Mac OS X users receive equal acknowledgment. The precautions and insights regarding subtle differences in Emacs when used on particular platforms can reduce users' frustration when getting started.
The mnemonic devices and conventions used in the book allow users to
commit useful keyboard commands to memory. The memorization is further
solidified by the exercises sprinkled appropriately through each
chapter. Readers do not go for very many pages before it is time to be
at the keyboard again, harnessing the power of muscle memory to
reinforce the material presented. Those who spend any time at a shell
prompt or in console applications will find that their new mastery of
Emacs keyboard shortcuts translates into increased proficiency with
command-line operations as well.
There is http://www.delorie.com/gnu/docs/emacs/viper_26.htm l/ for those wanting to return to the one true path (and avoidance of carpal tunnel syndrome).
The GNU Emacs Manual available for free at http://www.gnu.org/software/emacs/manual/ is excellent. Printed versions are available too.
Emacs also comes with a built-in tutorial that is a good interactive introduction to Emacs.
If you are considering learning Emacs, yes, it can seem like an intimidating task. The interface and commands are nothing like what people are used to today. But it is certainly worth the effort learning Emacs and getting used to it.
I'm in exactly the same boat. I don't consider myself to be stupid, but I've made serious efforts to learn Emacs (initially, just as a text editor), using the built in tutorial and previous editions of the O'Reilly book, and none of the keybindings, obscure combinations and long commands stick in my memory.
Vi wasn't easy to learn either -- but while unintuitive, it is all logical and most of the keybindings have obvious mnemonics.
I decided to give up on Emacs, and to be honest I've never been given a reason to regret it.
I've been using Emacs for 15 years and started using Emacs before I even knew that vi existed. I use vi when I must, i.e. no Emacs on the server or I'm going in on a slow remote connection, but don't want to use vi for my every day editing. I can do all the basic editing that I need in vi, but for the truly fancy stuff, I feel much more at home in Emacs.
;)
Automation of repetitive task can go way beyond recorded key strokes once you get a grip on Emacs lisp. This tool has saved me years of work over the time that I've used it.
The best way to learn Emacs is to just use it. Having this book will help you. I have the first edition now collecting dust on a shelf at home. The help, actually info, is very helpful. There's an interactive tutorial that comes with it, etc.
My favorite editor, though, must be sed.
Just be sure to wear the gold uniform when you beam down -- you know what happens when you wear the red one.
I like Emacs and its brethren, however, I don't do software development in Emacs anymore. Full blown IDEs like Eclipse are really worth the power, especially since they are able to semantically understand source code.
However, when I just need to do some basic config file editing I use Jove which is a scaled down version of Emacs that has the same keys as Emacs but loads as quickly as vi.
Emacs works great though when I have to interact in a complex way with the shell. For instance, I find it very useful when used in conjunction with command line SQL clients for Postgres, Mysql, or Oracle. The history and multiple command buffers are great for working with these command line clients. When I work with Oracle DBAs they are often impressed with how powerfully I can use SQLPlus from inside of Emacs.
I learned emacs in school, but by far the most helpful thing was the PDF reference card I printed up and carried with me. You can get the emacs card at http://refcards.com/
Physicists do it with a big bang!
Start with the most basic navigation commands. Learn to use "Ctrl-H, A" and type words in to learn about other commands you may need (e.g. "Ctrl-H, A, page" yields backward-page, forward-page, etc.)
The most useful thing I've ever done for my productivity, when it comes to Emacs, is to add the following line to my ~/.emacs file: So, when I type Ctrl-Z, it doesn't drop me into the shell (very annoying), but instead executes the last macro. Creating a macro is so easy and executing a gazillion iterations of a macro is now that much easier.
I've tried to switch to IDEs, to Kate (very, very nice), Quanta+ and others. But the power of the easy, fast macro keeps me coming back to Emacs, every time.
M-x viper-mode
(Meta or alt key plus x, then type viper-mode when prompterd). Now you have VI keybindings.
I don't really see why your right hand would hurt much, but still, here's my trick for Emacs hand comfort: make sure you use a keyboard where the left Control key sticks out well. That way, you can press Control with only the side of your hand, instead of having to use your pinky finger.
Think of this as a sixth finger for your hand. The shape of your hand was intelligently designed to use Emacs that way.
cheers
There is a Linux kernel module für emacs to make it start faster.
Look at the official Emacs FAQ.
Short answer, yes it does.
I run a shell in emacs (esc-x shell). It works great for searching through reams of command line job output and is slightly easier the piping to a file then searching through it (less, more etc...)
Its better than xterm -sl XYZ (set scroll lines to XYZ)
Emacs shell mixes up too much command input and output to my taste...
Then most shells (and every program using the readline library) support the Ctrl-R function to search through command history, just like emacs.
For searching through command outputs there are terminal emulators like konsole that provide such functions...
Check man readline you'll be surprised how much of emacs functionality you have in your daily shell!
Aquamacs (Carbon Emacs with settings to make it more Mac-like) cleans up a lot of that stuff. If you map meta to option, you can even use standard Mac keystrokes (command-S -> C-X C-S, command-Q -> C-X C-C, etc.). And SLIME works well under it - Aquamacs + Lisp-in-a-box without Emacs worked for me right out of the box (so to speak).
And, its default font is so much prettier...
To a Lisp hacker, XML is S-expressions in drag.
If you rebind the control input to the caps lock key (like the old style keyboards) then these 'crazy' keyboard combos become easier.
Yes, because typing L to go right, K to go up, J for down and H for left is so much more logical than ^F for forward, ^B for backward, ^N for the next line and ^P for the previous line! (I realize non-English speakers will be hosed either way.) Or that a linefeed character has a special status in vi, so you can't just delete it, you have to "join" the lines it separates. Or having to switch constantly between "navigating" and "inserting text," instead of just doing whichever you need to do right away.
This argument has been going on almost as long as the Catholic/Protestant thing. It seems once people get the habit of doing things one way, the other way is "strange" and "counterintuitive." Kind of like every other UI debate.
To answer the GP question: you can get by with about 10-15 basic commands. Open up emacs or xemacs, then type control-H followed by a t (no control). This gets you into the tutorial. Learn the basic navigation, editing and file commands. This will enable you to do all you need to do. Get comfortable with these first, because most of the special modes (like Dired, which lets you navigate directories) use the same keys for analogous operations). Also learn how to do M-x commands, like query-replace. After that, just learn new things a few at a time. The ones that are most useful to whatever you're doing will be the ones you remember.
It also helps to fix your keyboard. Try swapping cntl and caps lock if you're on a PC keyboard (the bane of emacs users), and using Alt as the meta key (great for the meta-based navigation).
As a die-hard Emacs fan, I would suggest that you stay with vi. You've got lots of experience with it, it's always available, the number of fans it has would indicate that Emacs can't be all that superior, etc.
Having said that, if you're still interested in learning Emacs, the best way to do it is cold turkey. You start using Emacs for your daily text-editing activities. All of them. Make yourself a cheat sheet, and stick it on the side of your monitor for easy reference.
Just try to get the basics at first. Simple navigation, selecting regions, cutting, pasting, and the saving and loading of files should be enough to get you started. Once you're comfortable with those, add in searching, switching between buffers, "autocomplete", find-and-replace, etc. Only add a couple of new features at a time, and give yourself time to make them instinctive before moving on.
One last thing: Don't touch the mouse. This will help you in the long run, as it will be an incentive to learn to navigate around a buffer. Avoiding the mouse will soon feel very natural.
My biggest hurdle with Emacs was the fact that I'd never used the Ctrl key, and I kept hitting Shift instead.
In summary, don't "take a few months off" to learn Emacs in its own right. You'll learn it better by simply using it for whatever project you're already working on. Remember that the learning curve is always steep when compared with sticking to the status quo, but don't be surprised if, once you get up the mountain, you find that you're approximately as productive as you were in vi.
You want the truthiness? You can't handle the truthiness!
For those who will fall for this: emacs was written in 1975, vi in 1976. So its very unlikely that emacs was written in response to vi, unless the MIT dudes had a time machine working. And vi was always free, it was written as part of BSD.
My favorite Emacs-specific ergo tip: avoid chording. It's not for nothing that Emacs is so massively configurable. I have:
.emacs (inspired by this.) I used to have a host of other things mapped all over the numeric keypad -- kill, yank, undo -- but I lost them at some point. I should re-create those.
(define-key global-map [f1] 'Control-X-prefix)
(define-key global-map [f2] 'find-file)
(define-key global-map [f3] 'save-buffer)
(define-key global-map [f4] 'kill-buffer)
(define-key global-map [f5] 'switch-to-buffer)
(define-key global-map [f6] 'other-window)
(define-key global-map [f9] 'compile)
in my
Also don't neglect a good setup (good posture, good keyboard, good pointing device), and stretch breaks at least once an hour.
Agreed, rebinding caps lock -> ctrl is a must. And type ctrl-[ instead of escape, since the escape key is usually hard to reach and anyway its position varies from keyboard to keyboard. ctrl-[ is also easier to reach than the alt key is (important for alt-x in Emacs).
Emacs supports composed characters, so it should be possible to support putting the tone marks in the right place, even if they are saved as seperate characters in the buffer. The problem is that the internationalization features of Emacs are a bit of a black art that very few people know enough about to do anything with.