EMACS To quote the Emacs Manual: Emacs is the extensible, customizable, self- documenting real-time display editor. Emacs is an editor for plain-text,
Post on 12-Jan-2016
EMACSTo quote the Emacs Manual:
Emacs is the extensible, customizable, self-documenting real-time display editor.
Emacs is an editor for plain-text, programming or markup languages, and anything else that someone has created a module for. Emacs also has tools for compiling, running and testing programs.
Emacs Commands * All of the basic editing commands (and there are lots of them) are available no matter what you're trying to do (there are no command modes like in vi to worry about) * All the tools Emacs provides for opening, saving, searching, and processing text (and more) are available to you no matter what you're in the middle of doing.
ExtensibilityIf Emacs doesn't work the way you'd like, you can use the Emacs Lisp (Elisp) language to customize Emacs, automate common tasks, or add new features. Elisp is very easy to get started with and yet remarkably powerful: you can use it to alter and extend almost any feature of Emacs. As an example, there are addons to emacs which allow you to read news, mail, and RSS feeds, manage your files, or even play Tetris! (good old M-x tetris)
Movement CommandsC means to press the C key and a keyM means to press the Meta key and a keyIf your terminal does not support a meta key, you can press ESC, release ESC, and then press the key to enter the meta command.
C-fForward one character C-bBack one characterC-nNext line C-pPrevious lineC-aBeginning of line C-eEnd of lineM-fForward one word M-bBack one wordM-aPrevious sentence M-eNext sentenceM-vPrevious screen C-vNext screenM-End of buffer
Getting fancy:C-u 3 C-pBack 3 linesC-u 10 C-fForward 10 charactersM-1 M-0 C-f Forward 10 charactersC-u C-nForward 4 linesC-u C-u C-nForward 16 linesC-u C-u C-u C-nForward 64 lines
M-g gJump to specified line
More advanced movementC-sIncremental search forwardC-rIncremental search backward
Emacs remembers something called the mark, which is a previous cursor position. You can set mark to indicate a particular place in your buffer so you can return to it easily. C-x C-x at a later time will return point to mark. Actually, that command also moves mark to where point formerly was; therefore, a second C-x C-x returns point to its original position.
C-SPCSet mark to the current locationC-x C-xSwap point and mark
Emacs tries to be helpful: many commands that have the potential to take you long distances set mark so that a simple C-x C-x takes you back to where you were. Emacs makes it difficult to lose your place in a buffer: even if you take a detour, you don't need to scroll around to get back to where you were.
Emacs saves many previous values of the mark for you. You can cycle through the mark ring, which contains the last 16 marks you've set in the current buffer:C-u C-SPCCycle through mark ring
Menu BarEmacs features a menu bar at the top of the screen which allows easy access to command commands.
On a graphical display, you can use your mouse to click on these toolbars as normal for GUI apps.
On a terminal display, you can press F10 to move to the first bar, and then navigate via arrow keys. Return selects, ESC cancels navigation.
Right arrows on the menu means that the item leads to another menu, ... on the menu means that the item will execute a command which will require input from the bottom of the window.
ScrollingC-l Clears the screen and redraws it, centering on the cursor.
C-v scroll forward (pagedown also works)
M-v scroll backwards (pageup works)
Windows! (Not the OS)Emacs has support for displaying multiple viewing windows at the same time.
C-x 2 Split the current window into 2, one above the other
C-x 3 Split the current window into 2, one next to the other
C-x o Switch focus to another window
C-x 0 delete the currently selected window
C-x 1 make the currently selected window the only window (delete / close others)
C-x ^ makes the current window taller
C-x } makes the current window wider
Killing / Cutting TextC-k kills the portion of the current line after point (or deletes the newline following point if point is at the end of line). The prefix argument for C-k can be used to kill multiple lines:C-kKill lineC-u 10 C-kKill 10 lines
The following commands operate on the region, and are the closest analogs to "cut" and "copy" in Emacs:C-wKill region ("cut")M-wSave region to kill ring without deleting ("copy")
These commands are also handy:M-dKill next wordM-kKill to end of sentence
All of the above commands kill the text being deleted, which means that Emacs removes the text and squirrels it away for later retrieval ("yanking"). Most commands which delete significant amounts of text kill it rather than simply removing it, so that you can use those commands either to "delete" text or to "cut" it for later use.
Yanking / Pasting TextAfter a piece of text has been killed, it goes to a place called the kill ring which is analogous to the "clipboard": you can yank an item to restore it from the kill ring with C-y. Unlike the clipboard, however, the kill ring is capable of holding many different items. If the item you want to yank is not placed when you type C-y, type M-y (repeatedly, if necessary) to cycle through previously killed items.C-yYanks last killed textM-yReplace yanked text with previously killed text
Recall that most commands which delete a large amount of text in fact kill it (i.e. place it in the kill ring) so you can restore it later. Emacs makes it very difficult to lose a lot of text permanently: in editors with only a single clipboard, one can easily accidentally delete a large chunk of text or clobber the contents of the clipboard (by cutting two items in succession). But in Emacs, in either of those cases, the lost text can easily be retrieved from the kill ring.
Undo!Aka, Uh-oh, where did my thesis go?
Many editors feature an Undo function, but commonly if you perform an Undo, then change some text, you are unable to Redo. Emacs however stores all actions, enabling you to do some things, undo them, do some other things, and then at any point undo over and over back to any of the previous states.
If this sounds complicated, just remember that "undo" is always capable of getting you back to any previous state your buffer was in (unless Emacs has run out of memory to store the undo history). The principle here is that Emacs makes it very difficult to accidentally lose your work.
Undo is available via three different keys:C-/UndoC-_UndoC-x uUndo
So if you need to get back to a previous buffer state, simply move the cursor (so as to break any existing sequence of undos), and press C-/ until you find what you want.
Search & ReplaceM-%Query replace
The query replace command prompts you for a search string and a replacement. Then, for each match in the buffer, you can choose whether or not to replace the search string. Here are some of the options available at each prompt:
* Type y to replace the current match. * Type n to skip to the next match without replacing. * Type q to exit without doing any more replacements. * Type . to replace this match, then exit. * Type ! to replace all remaining matches with no more questions.
Also, in addition to the search methods listed earlier, there exists:C-M-sRegular expression incremental search
Forgetting CommandsIf you don't remember what a particular key or command does, you can read a description of it by using one of the following commands:
C-h kShows documentation for the command associated with any particular key.
C-h fShows documentation for any particular command, by name (i.e. what you would type after M-x).
C-h a Allows a search for a feature you do not know exactly how to perform.
For example, C-h k C-s and C-h f isearch-forward RET both display a page describing incremental search.
ToolsM-x shell Starts a shell in the buffer named *shell*, switching to it if it already exists. Use C-u M-x shell to use a buffer with a different name.M-x compile Invokes make (with targets and options of your choice) and displays output in a new buffer. Emacs identifies error lines containing filenames and line numbers, and you can click on them to jump directly to the corresponding buffer and line.M-x grep Invokes grep and prints results in a new buffer. Like M-x compile, when you click on a match Emacs opens the correct file and takes you to the matching line.M-x man Displays man pages.M-x shell-command or M-! Executes a command and displays the output in a new buffer.
ModulesYou can switch modes in an existing buffer by using M-x and the name of the mode:M-x java-modeMode for editing Java filesM-x python-modeMode for editing Python filesM-x text-modeMode for editing text filesM-x fundamental-modeMode with no specializations at allM-x highlight-changes Mode which colors text added most recently
Emacs is very good at determining the right mode to use when you open a file so often these commands are unnecessary.
These are examples of the commands provided by language major modes:LanguageSome special commands availableLispManipulate s-exps in various ways; execute expressionsPythonIndent, unindent blocks; run code in Python shellHTMLInsert and close tags; preview in browser
In almost all cases, major modes for unsupported formats are available as extension packages. You can find many of them on EmacsWiki.
PortsThere are many different builds of Emacs available freely online. The source code is also available online.
Emacs is built on many Linux distros, Windows, DOS, OSX, and others.
Emacs exists in terminal, Xwindow, and other GUI flavors.