Emacs: A User's Best Friend
On any Linux or UNIX environment, text editing becomes an essential activity; sooner or later you'll need to edit a text file to get something done. Perhaps you're editing the “php.ini” configuration file to get specific functionality within your PHP package or, to get a certain program to run when you start up your window manager, your “.xinitrc” file. When you find yourself creating or altering many text files on a regular basis, it'll behoove you to learn a capable text editor. Programmers understand the need to develop a close relationship with their code editors. After all, when you're crafting and shifting code for hours on end, you'll need a powerful, competent text editor to work like a well oiled machine.
There're two devout text editor camps, each one often engaged in flame wars and petty arguments with each other. Some people prefer “Vi”; others prefer “Emacs” for their text editing needs. Search Usenet or its web archive, Google Groups, for an innumerable amount of pros and cons for each of these editors, and you'll find a multitude of personal reasons on why one would choose one over the other. I've used both, and I'm partial to Emacs; it fits me like an old pair of comfortable, broken-in shoes.
One of the many cool things about Emacs is this: once you learn a few key bindings—key strokes bound to a command to accomplish a task—you'll never again have to reach for the mouse to do anything; everything you'll ever need can be summoned at your whim from the keyboard. It's a liberating feeling, and you'll be surprised at how much this can improve your productivity. Reaching for the mouse to manipulate the cursor or cutting and pasting a portion of text can significantly hinder your work flow. Doing these sorts of operations every couple of minutes or so can turn your “in the zone” mentality into a cumbersome, slow march through a thick, sweltering jungle. You'll be amazed at how productive you'll become once you decide to take Emacs for a spin.
Have you ever seen a person who's really proficient at Emacs? It's a sight to see their nimble fingers dancing at swift speeds across their keyboard. While their fingers bewitchingly charm the keyboard, mountains of text are created, folded, spindled, and sliced inside of an Emacs window, hypnotic in fashion, all without the aid of a mouse. “We don't need any mice!” they shout as they play a game of Tetris inside of an Emacs frame (enter M-x tetris to play).
You probably already have Emacs installed on your system, so fire it up by typing “emacs” inside of a shell. Emacs immediately places you inside of a scratch text buffer; this is the perfect place to learn a few essential Emacs commands. Type a few lines of gibberish so that you can practice on it. A few things need to be mentioned before we begin. Emacs uses two main keys that let it know that you want to execute a command. These keys are usually the CONTROL and ALT keys. The CONTROL key will be abbreviated with a “C” and, for a historical reason, the ALT key will be an “M”, which stands for “meta key”. So, C-f means to hold down the CONTROL key while pressing the “f” key, and M-x means to hold down the ALT key while pressing “x”. Got it? Cool, let's continue.
Let's learn to move around an Emacs buffer since it's such an important operation. You can move one character forward with “C-f”. Try it out. “C-b” will move you one character back. “C-p” will move you up one line, while “C-n” will move you down a line. If you wish to jump to the beginning of a line, “C-a” will do this quite nicely. Jump to the end of the line with “C-e”; it's easy to remember that “C-a” jumps to the beginning of a line because “a” begins our beloved English alphabet and “C-e” for the end of a line because “e” starts the word “end”. Once you've mastered these basic navigation key bindings, you'll never need the assistance of the mouse again. By the way, this helps when you don't have access to a GUI window manager and you have to edit a file without mouse support.
Ok, now that you've got the rudimentary navigation functions down, let's actually start working with text. I cut and paste a lot. I'm always moving around blocks of text here and there. To copy a portion of text you have to do something called “marking” it. When you mark a block of text, you're telling Emacs that you wish to do something with it, like copying or cutting, for example. To begin the “mark”, start at the section you want to copy and do a “C-space” (control-spacebar); this will start the mark. Now move to the section that will end the mark with any of the navigation commands. You should see a transient highlight around the portion you marked off. If all is well, copy the text with an “M-w”. The highlight should disappear; this means that you've successfully copied the text and that it's ready to be pasted; do a “C-y” to paste. Move to any section of the buffer and go paste crazy. Practice marking arbitrary text regions to copy, and paste them to get the hang of it. If you would rather cut the section of text, do a “C-w”.
You should now know the basics of moving around in Emacs, how to mark a region, and how to cut and paste a marked region of text; that's basically all you need to know to edit text in Emacs. Once you're done editing, you may wish to save your work. “C-x-s” will save the contents of the file to disk. Ok, you're file is nicely edited. You're happy and your file is happy. It's time to go home. “C-x-c” will exit Emacs and dump you back into your shell.
Emacs is a massive program that can do a lot more; if you want to study up on it, do a “C-h t”. This command will pull up the Emacs tutorial for you to read at your leisure. It's a great primer to the wonderful world of Emacs. Happy editing!
More On Linux
-Partition Your Hard Drive For Linux
-Make A Start Up Disk For Linux
-Touring the Linux File System
Back To Tips Homepage
How To Build A PC | Different Types of Keyboards | Help with Hard Drive Installation | Computer Networking Basics | Introduction of Motherboard Functions | Computer CPU Processor Speed | Upgrade from Windows 95 to Windows 98 | Computer Monitor Troubleshoot | Partition Hard Drive | Installing New CPU Processor | Types of Network Cables